From 749ba979f4cd80a0d8e7023e910c848bbf465d88 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Mon, 22 Aug 2022 18:48:47 +0300 Subject: [PATCH] [SSE] Search: send selected result item --- apps/common/main/lib/view/SearchPanel.js | 6 +++-- .../main/app/controller/Search.js | 25 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/common/main/lib/view/SearchPanel.js b/apps/common/main/lib/view/SearchPanel.js index d0170ce25..4bb2bd81c 100644 --- a/apps/common/main/lib/view/SearchPanel.js +++ b/apps/common/main/lib/view/SearchPanel.js @@ -335,7 +335,8 @@ define([ } else { text = current === 'no-results' ? this.textNoSearchResults : (current === 'stop' ? this.textSearchHasStopped : - (!count ? this.textNoMatches : Common.Utils.String.format(this.textSearchResults, current + 1, count))); + (current === 'content-changed' ? this.textContentChanged : + (!count ? this.textNoMatches : Common.Utils.String.format(this.textSearchResults, current + 1, count)))); } this.$reaultsNumber.text(text); !window.SSE && this.disableReplaceButtons(!count); @@ -422,7 +423,8 @@ define([ textCell: 'Cell', textValue: 'Value', textFormula: 'Formula', - textSearchHasStopped: 'Search has stopped' + textSearchHasStopped: 'Search has stopped', + textContentChanged: 'Document content has changed.' }, Common.Views.SearchPanel || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/controller/Search.js b/apps/spreadsheeteditor/main/app/controller/Search.js index cd4854748..66909cde0 100644 --- a/apps/spreadsheeteditor/main/app/controller/Search.js +++ b/apps/spreadsheeteditor/main/app/controller/Search.js @@ -93,7 +93,9 @@ define([ withinSheet: Asc.c_oAscSearchBy.Sheet, searchByRows: true, lookInFormulas: true, - isValidSelectedRange: true + isValidSelectedRange: true, + lastSelectedItem: undefined, + isContentChanged: false }; }, @@ -111,8 +113,8 @@ define([ this.api.asc_registerCallback('asc_onEndTextAroundSearch', _.bind(this.onEndTextAroundSearch, this)); this.api.asc_registerCallback('asc_onGetTextAroundSearchPack', _.bind(this.onApiGetTextAroundSearch, this)); this.api.asc_registerCallback('asc_onRemoveTextAroundSearch', _.bind(this.onApiRemoveTextAroundSearch, this)); - this.api.asc_registerCallback('asc_onSearchEnd', _.bind(this.onApiSearchEnd, this)); this.api.asc_registerCallback('asc_onActiveSheetChanged', _.bind(this.onActiveSheetChanged, this)); + this.api.asc_registerCallback('asc_onModifiedDocument', _.bind(this.onApiModifiedDocument, this)); } return this; }, @@ -259,6 +261,8 @@ define([ return; } + this._state.isContentChanged = false; + var options = new Asc.asc_CFindOptions(); options.asc_setFindWhat(this._state.searchText); options.asc_setScanForward(d != 'back'); @@ -271,6 +275,7 @@ 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); + options.asc_setLastSearchElem(this._state.lastSelectedItem); if (!this.api.asc_findText(options)) { this.resultItems = []; this.view.updateResultsNumber(undefined, 0); @@ -296,6 +301,7 @@ define([ } options.asc_setScanByRows(this._state.searchByRows); options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); + options.asc_setLastSearchElem(this._state.lastSelectedItem); options.asc_setIsReplaceAll(false); this.api.asc_replaceText(options); @@ -314,6 +320,7 @@ define([ } options.asc_setScanByRows(this._state.searchByRows); options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); + options.asc_setLastSearchElem(this._state.lastSelectedItem); options.asc_setIsReplaceAll(true); this.api.asc_replaceText(options); @@ -345,6 +352,7 @@ define([ } options.asc_setScanByRows(this._state.searchByRows); options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); + options.asc_setLastSearchElem(this._state.lastSelectedItem); if (!this.api.asc_findText(options)) { this.removeResultItems(); } @@ -384,6 +392,7 @@ define([ item.selected = false; }); if (this.resultItems[current]) { + this._state.lastSelectedItem = this.resultItems[current].data; this.resultItems[current].selected = true; $('#search-results').find('.item').removeClass('selected'); this.resultItems[current].$el.addClass('selected'); @@ -443,9 +452,14 @@ define([ if (isSelected) { $item.addClass('selected'); } - var resultItem = {id: item[0], $el: $item, el: tr, selected: isSelected, data: data}; + var resultItem = {id: item[0], $el: $item, el: tr, selected: isSelected, data: item}; me.resultItems.push(resultItem); $item.on('click', _.bind(function (el) { + if (me._state.isContentChanged) { + me._state.lastSelectedItem = item; + me.onQuerySearch(); + return; + } var id = item[0]; me.api.asc_SelectSearchElement(id); }, me)); @@ -551,8 +565,9 @@ define([ } }, - onApiSearchEnd: function () { - this.removeResultItems('stop'); + onApiModifiedDocument: function () { + this._state.isContentChanged = true; + this.view.updateResultsNumber('content-changed'); }, onActiveSheetChanged: function (index) {