diff --git a/apps/documenteditor/main/app/controller/Search.js b/apps/documenteditor/main/app/controller/Search.js index df7ca46a9..38d2de4ab 100644 --- a/apps/documenteditor/main/app/controller/Search.js +++ b/apps/documenteditor/main/app/controller/Search.js @@ -118,6 +118,29 @@ define([ this.view : Backbone.Controller.prototype.getView.call(this, name); }, + checkPunctuation: function (text) { + if (!!text) { + var isPunctuation = false; + for (var l = 0; l < text.length; l++) { + var charCode = text.charCodeAt(l), + char = text.charAt(l); + if (AscCommon.g_aPunctuation[charCode] !== undefined || char.trim() === '') { + isPunctuation = true; + break; + } + } + if (isPunctuation) { + if (this._state.matchWord) { + this.view.chMatchWord.setValue(false, true); + this._state.matchWord = false; + } + this.view.chMatchWord.setDisabled(true); + } else if (this.view.chMatchWord.isDisabled()) { + this.view.chMatchWord.setDisabled(false); + } + } + }, + onChangeSearchOption: function (option, checked) { switch (option) { case 'case-sensitive': @@ -138,6 +161,7 @@ define([ onSearchNext: function (type, text, e) { var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN; if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) { + this.checkPunctuation(text); this._state.searchText = text; this.onQuerySearch(type, !(this.searchTimer || isReturnKey)); } @@ -152,6 +176,7 @@ define([ this.searchTimer = setInterval(function(){ if ((new Date()) - me._lastInputChange < 400) return; + me.checkPunctuation(me._state.newSearchText); me._state.searchText = me._state.newSearchText; if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') { me.view.updateResultsNumber('no-results'); @@ -370,6 +395,7 @@ define([ var selectedText = this.api.asc_GetSelectedText(), text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText); + this.checkPunctuation(text); if (this.resultItems && this.resultItems.length > 0 && (!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() || this._state.matchCase && text === this.view.inputText.getValue())) { // show old results diff --git a/apps/presentationeditor/main/app/controller/Search.js b/apps/presentationeditor/main/app/controller/Search.js index 1e89fecfb..a948ecc63 100644 --- a/apps/presentationeditor/main/app/controller/Search.js +++ b/apps/presentationeditor/main/app/controller/Search.js @@ -132,9 +132,33 @@ define([ } }, + checkPunctuation: function (text) { + if (!!text) { + var isPunctuation = false; + for (var l = 0; l < text.length; l++) { + var charCode = text.charCodeAt(l), + char = text.charAt(l); + if (AscCommon.g_aPunctuation[charCode] !== undefined || char.trim() === '') { + isPunctuation = true; + break; + } + } + if (isPunctuation) { + if (this._state.matchWord) { + this.view.chMatchWord.setValue(false, true); + this._state.matchWord = false; + } + this.view.chMatchWord.setDisabled(true); + } else if (this.view.chMatchWord.isDisabled()) { + this.view.chMatchWord.setDisabled(false); + } + } + }, + onSearchNext: function (type, text, e) { var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN; if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) { + this.checkPunctuation(text); this._state.searchText = text; this.onQuerySearch(type, !(this.searchTimer || isReturnKey)); } @@ -149,6 +173,7 @@ define([ this.searchTimer = setInterval(function(){ if ((new Date()) - me._lastInputChange < 400) return; + me.checkPunctuation(me._state.newSearchText); me._state.searchText = me._state.newSearchText; if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') { me.view.updateResultsNumber('no-results'); @@ -336,6 +361,7 @@ define([ var selectedText = this.api.asc_GetSelectedText(), text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText); + this.checkPunctuation(text); if (text) { this.view.setFindText(text); } else if (text !== undefined) { // panel was opened from empty searchbar, clear to start new search