diff --git a/apps/common/main/lib/view/SearchPanel.js b/apps/common/main/lib/view/SearchPanel.js index 11dc0ebdb..cb43db898 100644 --- a/apps/common/main/lib/view/SearchPanel.js +++ b/apps/common/main/lib/view/SearchPanel.js @@ -210,6 +210,7 @@ define([ }).on('keyup:after', function(input, e) { me.fireEvent('search:options', ['range', input.getValue(), e.keyCode !== Common.UI.Keys.RETURN]); }); + this.inputSelectRange.$el.hide(); this.cmbSearch = new Common.UI.ComboBox({ el: $('#search-adv-cmb-search'), @@ -437,8 +438,8 @@ define([ textValue: 'Value', textFormula: 'Formula', textSearchHasStopped: 'Search has stopped', - textContentChanged: 'Document content has changed.', - textSearchAgain: '{0}Search again{1} to make sure the results are current.' + textContentChanged: 'Document changed.', + textSearchAgain: '{0}Perform new search{1} for accurate results.' }, Common.Views.SearchPanel || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index 157c97cd6..1a9e70001 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -719,7 +719,7 @@ define([ if (this.isSearchPanelVisible()) { selectedText && this.leftMenu.panelSearch.setFindText(selectedText); this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search'); - this.leftMenu.fireEvent('search:aftershow', this.leftMenu, selectedText); + this.leftMenu.fireEvent('search:aftershow', this.leftMenu, selectedText ? selectedText : undefined); return false; } else if (this.getApplication().getController('Viewport').isSearchBarVisible()) { var viewport = this.getApplication().getController('Viewport'); @@ -735,10 +735,10 @@ define([ Common.NotificationCenter.trigger('search:show'); return false; } else { - this.onShowHideSearch(true, selectedText); + this.onShowHideSearch(true, selectedText ? selectedText : undefined); } this.leftMenu.btnSearchBar.toggle(true,true); - this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search'); + this.leftMenu.panelSearch.focus(selectedText ? s : 'search'); // this.leftMenu.menuFile.hide(); return false; case 'save': diff --git a/apps/documenteditor/main/app/controller/Search.js b/apps/documenteditor/main/app/controller/Search.js index 579106502..df7ca46a9 100644 --- a/apps/documenteditor/main/app/controller/Search.js +++ b/apps/documenteditor/main/app/controller/Search.js @@ -90,7 +90,8 @@ define([ matchCase: false, matchWord: false, useRegExp: false, - isHighlightedResults: false + isHighlightedResults: false, + isContentChanged: false }; }, @@ -130,14 +131,7 @@ define([ break; } if (this._state.searchText) { - this.hideResults(); - if (this.onQuerySearch()) { - if (this.searchTimer) { - clearInterval(this.searchTimer); - this.searchTimer = undefined; - } - this.api.asc_StartTextAroundSearch(); - } + this.onQuerySearch(); } }, @@ -145,16 +139,7 @@ define([ var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN; if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) { this._state.searchText = text; - if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) { - this.hideResults(); - if (this.searchTimer) { - clearInterval(this.searchTimer); - this.searchTimer = undefined; - } - if (this.view.$el.is(':visible')) { - this.api.asc_StartTextAroundSearch(); - } - } + this.onQuerySearch(type, !(this.searchTimer || isReturnKey)); } }, @@ -167,26 +152,26 @@ define([ this.searchTimer = setInterval(function(){ if ((new Date()) - me._lastInputChange < 400) return; - me.hideResults(); me._state.searchText = me._state.newSearchText; - if (me._state.newSearchText !== '' && me.onQuerySearch()) { - if (me.view.$el.is(':visible')) { - me.api.asc_StartTextAroundSearch(); - } - me.view.disableReplaceButtons(false); - } else if (me._state.newSearchText === '') { + if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') { me.view.updateResultsNumber('no-results'); me.view.disableNavButtons(); me.view.disableReplaceButtons(true); + clearInterval(me.searchTimer); + me.searchTimer = undefined; } - clearInterval(me.searchTimer); - me.searchTimer = undefined; }, 10); } } }, - onQuerySearch: function (d, w) { + onQuerySearch: function (d, noUpdate) { + var update = !noUpdate || this._state.isContentChanged; + this._state.isContentChanged = false; + this.searchTimer && clearInterval(this.searchTimer); + this.searchTimer = undefined; + update && this.hideResults(); + var searchSettings = new AscCommon.CSearchSettings(); searchSettings.put_Text(this._state.searchText); searchSettings.put_MatchCase(this._state.matchCase); @@ -200,6 +185,10 @@ define([ this.view.disableNavButtons(); return false; } + if (update && this.view.$el.is(':visible')) { + this.api.asc_StartTextAroundSearch(); + } + this.view.disableReplaceButtons(false); return true; }, @@ -324,7 +313,8 @@ define([ onApiGetTextAroundSearch: function (data) { if (this.view && this._state.isStartedAddingResults) { if (data.length > 300 || !data.length) return; - var me = this; + var me = this, + selectedInd; me.resultItems = []; data.forEach(function (item, ind) { var el = document.createElement("div"), @@ -334,17 +324,23 @@ define([ me.view.$resultsContainer.append(el); if (isSelected) { $(el).addClass('selected'); + selectedInd = ind; } var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected}; me.resultItems.push(resultItem); $(el).on('click', _.bind(function (el) { + if (me._state.isContentChanged) { + me.onQuerySearch(); + return; + } var id = item[0]; me.api.asc_SelectSearchElement(id); }, me)); }); this.view.$resultsContainer.show(); + this.scrollToSelectedResult(selectedInd); } }, @@ -433,7 +429,11 @@ define([ }, onApiSearchEnd: function () { - this.removeResultItems('stop'); + if (!this._state.isContentChanged) { + this._state.isContentChanged = true; + this.view.updateResultsNumber('content-changed'); + this.view.disableReplaceButtons(true); + } }, onApiTextReplaced: function(found, replaced) { diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index c977040e3..87d502782 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -485,6 +485,8 @@ "Common.Views.SearchPanel.textWholeWords": "Whole words only", "Common.Views.SearchPanel.tipNextResult": "Next result", "Common.Views.SearchPanel.tipPreviousResult": "Previous result", + "Common.Views.SearchPanel.textContentChanged": "Document changed.", + "Common.Views.SearchPanel.textSearchAgain": "{0}Perform new search{1} for accurate results.", "Common.Views.SelectFileDlg.textLoading": "Loading", "Common.Views.SelectFileDlg.textTitle": "Select Data Source", "Common.Views.SignDialog.textBold": "Bold", diff --git a/apps/presentationeditor/main/app/controller/LeftMenu.js b/apps/presentationeditor/main/app/controller/LeftMenu.js index 6c679b346..c41b6fed9 100644 --- a/apps/presentationeditor/main/app/controller/LeftMenu.js +++ b/apps/presentationeditor/main/app/controller/LeftMenu.js @@ -562,7 +562,7 @@ define([ if (this.isSearchPanelVisible()) { selectedText && this.leftMenu.panelSearch.setFindText(selectedText); this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search'); - this.leftMenu.fireEvent('search:aftershow', this.leftMenu, selectedText); + this.leftMenu.fireEvent('search:aftershow', this.leftMenu, selectedText ? selectedText : undefined); return false; } else if (this.getApplication().getController('Viewport').isSearchBarVisible()) { var viewport = this.getApplication().getController('Viewport'); @@ -578,10 +578,10 @@ define([ Common.NotificationCenter.trigger('search:show'); return false; } else { - this.onShowHideSearch(true, selectedText); + this.onShowHideSearch(true, selectedText ? selectedText : undefined); } this.leftMenu.btnSearchBar.toggle(true,true); - this.leftMenu.panelSearch.focus(s); + this.leftMenu.panelSearch.focus(selectedText ? s : 'search'); } return false; case 'save': diff --git a/apps/presentationeditor/main/app/controller/Search.js b/apps/presentationeditor/main/app/controller/Search.js index 7c242c2ab..1e89fecfb 100644 --- a/apps/presentationeditor/main/app/controller/Search.js +++ b/apps/presentationeditor/main/app/controller/Search.js @@ -87,7 +87,8 @@ define([ searchText: '', matchCase: false, matchWord: false, - useRegExp: false + useRegExp: false, + isContentChanged: false }; }, @@ -127,14 +128,7 @@ define([ break; } if (this._state.searchText) { - this.hideResults(); - if (this.onQuerySearch()) { - if (this.searchTimer) { - clearInterval(this.searchTimer); - this.searchTimer = undefined; - } - this.api.asc_StartTextAroundSearch(); - } + this.onQuerySearch(); } }, @@ -142,16 +136,7 @@ define([ var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN; if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) { this._state.searchText = text; - if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) { - this.hideResults(); - if (this.searchTimer) { - clearInterval(this.searchTimer); - this.searchTimer = undefined; - } - if (this.view.$el.is(':visible')) { - this.api.asc_StartTextAroundSearch(); - } - } + this.onQuerySearch(type, !(this.searchTimer || isReturnKey)); } }, @@ -164,26 +149,26 @@ define([ this.searchTimer = setInterval(function(){ if ((new Date()) - me._lastInputChange < 400) return; - me.hideResults(); me._state.searchText = me._state.newSearchText; - if (me._state.newSearchText !== '' && me.onQuerySearch()) { - if (me.view.$el.is(':visible')) { - me.api.asc_StartTextAroundSearch(); - } - me.view.disableReplaceButtons(false); - } else if (me._state.newSearchText === '') { + if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') { me.view.updateResultsNumber('no-results'); me.view.disableNavButtons(); me.view.disableReplaceButtons(true); + clearInterval(me.searchTimer); + me.searchTimer = undefined; } - clearInterval(me.searchTimer); - me.searchTimer = undefined; }, 10); } } }, - onQuerySearch: function (d, w) { + onQuerySearch: function (d, noUpdate) { + var update = !noUpdate || this._state.isContentChanged; + this._state.isContentChanged = false; + this.searchTimer && clearInterval(this.searchTimer); + this.searchTimer = undefined; + update && this.hideResults(); + var searchSettings = new AscCommon.CSearchSettings(); searchSettings.put_Text(this._state.searchText); searchSettings.put_MatchCase(this._state.matchCase); @@ -197,6 +182,11 @@ define([ this.view.disableNavButtons(); return false; } + + if (update && this.view.$el.is(':visible')) { + this.api.asc_StartTextAroundSearch(); + } + this.view.disableReplaceButtons(false); return true; }, @@ -289,7 +279,8 @@ define([ onApiGetTextAroundSearch: function (data) { if (this.view && this._state.isStartedAddingResults) { if (data.length > 300 || !data.length) return; - var me = this; + var me = this, + selectedInd; me.resultItems = []; data.forEach(function (item, ind) { var el = document.createElement("div"), @@ -299,17 +290,23 @@ define([ me.view.$resultsContainer.append(el); if (isSelected) { $(el).addClass('selected'); + selectedInd = ind; } var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected}; me.resultItems.push(resultItem); $(el).on('click', _.bind(function (el) { + if (me._state.isContentChanged) { + me.onQuerySearch(); + return; + } var id = item[0]; me.api.asc_SelectSearchElement(id); }, me)); }); this.view.$resultsContainer.show(); + this.scrollToSelectedResult(selectedInd); } }, @@ -382,7 +379,11 @@ define([ }, onApiSearchEnd: function () { - this.removeResultItems('stop'); + if (!this._state.isContentChanged) { + this._state.isContentChanged = true; + this.view.updateResultsNumber('content-changed'); + this.view.disableReplaceButtons(true); + } }, onApiTextReplaced: function(found, replaced) { diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index 666c5d962..d86849349 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -561,6 +561,8 @@ "Common.Views.SearchPanel.textWholeWords": "Whole words only", "Common.Views.SearchPanel.tipNextResult": "Next result", "Common.Views.SearchPanel.tipPreviousResult": "Previous result", + "Common.Views.SearchPanel.textContentChanged": "Document changed.", + "Common.Views.SearchPanel.textSearchAgain": "{0}Perform new search{1} for accurate results.", "Common.Views.SelectFileDlg.textLoading": "Loading", "Common.Views.SelectFileDlg.textTitle": "Select Data Source", "Common.Views.SignDialog.textBold": "Bold", diff --git a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js index 8a9389bd5..edbc33b2a 100644 --- a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js @@ -692,7 +692,7 @@ define([ if (this.isSearchPanelVisible()) { selectedText && this.leftMenu.panelSearch.setFindText(selectedText); this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search'); - this.leftMenu.fireEvent('search:aftershow', [selectedText]); + this.leftMenu.fireEvent('search:aftershow', [selectedText ? selectedText : undefined]); return false; } else if (this.getApplication().getController('Viewport').isSearchBarVisible()) { var viewport = this.getApplication().getController('Viewport'); @@ -708,10 +708,10 @@ define([ Common.NotificationCenter.trigger('search:show'); return false; } else { - this.onShowHideSearch(true, selectedText); + this.onShowHideSearch(true, selectedText ? selectedText : undefined); } this.leftMenu.btnSearchBar.toggle(true,true); - this.leftMenu.panelSearch.focus(selectedText !== '' ? s : 'search'); + this.leftMenu.panelSearch.focus(selectedText ? s : 'search'); } return false; case 'save': diff --git a/apps/spreadsheeteditor/main/app/controller/Search.js b/apps/spreadsheeteditor/main/app/controller/Search.js index bb60e2949..534684f04 100644 --- a/apps/spreadsheeteditor/main/app/controller/Search.js +++ b/apps/spreadsheeteditor/main/app/controller/Search.js @@ -153,8 +153,10 @@ define([ this._state.withinSheet = value === 0 ? Asc.c_oAscSearchBy.Sheet : (value === 1 ? Asc.c_oAscSearchBy.Workbook : Asc.c_oAscSearchBy.Range); this.view.inputSelectRange.setDisabled(value !== Asc.c_oAscSearchBy.Range); if (value === Asc.c_oAscSearchBy.Range) { - runSearch = false; + runSearch = this._state.isValidSelectedRange && !!this._state.selectedRange; } + this.view.inputSelectRange.$el[value === Asc.c_oAscSearchBy.Range ? 'show' : 'hide'](); + this.view.updateResultsContainerHeight(); break; case 'range': this._state.selectedRange = value; @@ -257,8 +259,11 @@ define([ options.asc_setScanByRows(this._state.searchByRows); options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); options.asc_setNeedRecalc(isNeedRecalc); - this._state.isContentChanged && options.asc_setLastSearchElem(this._state.lastSelectedItem); - this._state.isContentChanged = false; + if (this._state.isContentChanged) { + options.asc_setLastSearchElem(this._state.lastSelectedItem); + this.view.disableReplaceButtons(false); + this._state.isContentChanged = false; + } if (!this.api.asc_findText(options)) { this.removeResultItems(); return false; @@ -271,10 +276,6 @@ define([ }, onQueryReplace: function(textSearch, textReplace) { - if (this._state.isContentChanged) { - this.onQuerySearch(); - return; - } this.api.isReplaceAll = false; var options = new Asc.asc_CFindOptions(); options.asc_setFindWhat(textSearch); @@ -293,10 +294,6 @@ define([ }, onQueryReplaceAll: function(textSearch, textReplace) { - if (this._state.isContentChanged) { - this.onQuerySearch(); - return; - } this.api.isReplaceAll = true; var options = new Asc.asc_CFindOptions(); options.asc_setFindWhat(textSearch); @@ -545,6 +542,7 @@ define([ onApiModifiedDocument: function () { this._state.isContentChanged = true; this.view.updateResultsNumber('content-changed'); + this.view.disableReplaceButtons(true); }, onActiveSheetChanged: function (index) { diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 11f8a3328..930e87b49 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -423,8 +423,8 @@ "Common.Views.SearchPanel.textWorkbook": "Workbook", "Common.Views.SearchPanel.tipNextResult": "Next result", "Common.Views.SearchPanel.tipPreviousResult": "Previous result", - "Common.Views.SearchPanel.textContentChanged": "Document content has changed.", - "Common.Views.SearchPanel.textSearchAgain": "{0}Search again{1} to make sure the results are current.", + "Common.Views.SearchPanel.textContentChanged": "Document changed.", + "Common.Views.SearchPanel.textSearchAgain": "{0}Perform new search{1} for accurate results.", "Common.Views.SelectFileDlg.textLoading": "Loading", "Common.Views.SelectFileDlg.textTitle": "Select Data Source", "Common.Views.SignDialog.textBold": "Bold", diff --git a/apps/spreadsheeteditor/main/resources/less/leftmenu.less b/apps/spreadsheeteditor/main/resources/less/leftmenu.less index 7f4accae5..b705dfc6d 100644 --- a/apps/spreadsheeteditor/main/resources/less/leftmenu.less +++ b/apps/spreadsheeteditor/main/resources/less/leftmenu.less @@ -772,7 +772,7 @@ } } .search-items { - height: calc(100% - 24px); + height: calc(100% - 28px); position: absolute; top: 28px; width: 100%;