From 1f708c1d2fd17f91759f1c4af9244a17c5c82905 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Thu, 25 Aug 2022 15:21:09 +0300 Subject: [PATCH 1/2] [SSE] Fix bug 58700 --- apps/spreadsheeteditor/main/app/controller/Search.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/spreadsheeteditor/main/app/controller/Search.js b/apps/spreadsheeteditor/main/app/controller/Search.js index 534684f04..e73f46fc6 100644 --- a/apps/spreadsheeteditor/main/app/controller/Search.js +++ b/apps/spreadsheeteditor/main/app/controller/Search.js @@ -349,6 +349,9 @@ define([ me.resultItems.splice(ind, 1); } }); + if (this.resultItems.length === 0) { + this.removeResultItems(); + } }, onUpdateSearchCurrent: function (current, all) { From 15b76b68b2e022cfa71b419b88aed9cc604dcc7f Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Thu, 25 Aug 2022 21:37:10 +0300 Subject: [PATCH 2/2] [SSE] Search empty cells only by enter --- apps/common/main/lib/view/SearchBar.js | 1 + .../main/app/controller/Search.js | 66 ++++++++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/apps/common/main/lib/view/SearchBar.js b/apps/common/main/lib/view/SearchBar.js index fbd279570..9437be55d 100644 --- a/apps/common/main/lib/view/SearchBar.js +++ b/apps/common/main/lib/view/SearchBar.js @@ -145,6 +145,7 @@ define([ this.fireEvent('search:input', [text]); } else { this.inputSearch.val(''); + window.SSE && this.fireEvent('search:input', ['', true]); } this.focus(); diff --git a/apps/spreadsheeteditor/main/app/controller/Search.js b/apps/spreadsheeteditor/main/app/controller/Search.js index e73f46fc6..f615ab4dc 100644 --- a/apps/spreadsheeteditor/main/app/controller/Search.js +++ b/apps/spreadsheeteditor/main/app/controller/Search.js @@ -57,7 +57,14 @@ define([ 'SearchBar': { 'search:back': _.bind(this.onSearchNext, this, 'back'), 'search:next': _.bind(this.onSearchNext, this, 'next'), - 'search:input': _.bind(function (text) { + 'search:input': _.bind(function (text, afterShow) { + if (afterShow && !text) { + if (this._state.isResults) { + this._state.noSearchEmptyCells = true; + this.onQuerySearch(); + } + return; + } if (this._state.searchText === text) { Common.NotificationCenter.trigger('search:updateresults', this._state.currentResult, this._state.resultsNumber); return; @@ -79,7 +86,7 @@ define([ 'show': _.bind(this.onShowPanel, this), 'hide': _.bind(this.onHidePanel, this) }, - 'LeftMenu': { // TO DO + 'LeftMenu': { 'search:aftershow': _.bind(this.onShowAfterSearch, this) } }); @@ -95,7 +102,10 @@ define([ lookInFormulas: true, isValidSelectedRange: true, lastSelectedItem: undefined, - isContentChanged: false + isContentChanged: false, + isResults: false, + noSearchEmptyCells: false, + isReturnPressed: false }; }, @@ -206,9 +216,14 @@ define([ this._state.searchText = text; this.onQuerySearch(type); } + this._state.isReturnPressed = isReturnKey; }, onInputSearchChange: function (text) { + if (!text && !this._state.isReturnPressed) { + this._state.noSearchEmptyCells = true; + } + this._state.isReturnPressed = false; var me = this; if (this._state.searchText !== text) { this._state.newSearchText = text; @@ -263,12 +278,22 @@ define([ options.asc_setLastSearchElem(this._state.lastSelectedItem); this.view.disableReplaceButtons(false); this._state.isContentChanged = false; + if (!this.view.$el.is(':visible')) { + this.resultItems = []; + } } + options.asc_setNotSearchEmptyCells(this._state.noSearchEmptyCells); if (!this.api.asc_findText(options)) { - this.removeResultItems(); + this._state.isResults = false; + if (this._state.noSearchEmptyCells) { + this.removeResultItems('no-results'); + this._state.noSearchEmptyCells = false; + } else { + this.removeResultItems(); + } return false; } - + this._state.isResults = true; if (this.view.$el.is(':visible')) { this.api.asc_StartTextAroundSearch(); } @@ -473,31 +498,40 @@ define([ }, onShowAfterSearch: function (findText) { - var viewport = this.getApplication().getController('Viewport'); + var fromEmptySearchBar = findText === '', + viewport = this.getApplication().getController('Viewport'); if (viewport.isSearchBarVisible()) { viewport.searchBar.hide(); } var selectedText = this.api.asc_GetSelectedText(), text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText); - if (this.resultItems && this.resultItems.length > 0 && - (!text && !this.view.inputText.getValue() || - !this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() || - this._state.matchCase && text === this.view.inputText.getValue())) { // show old results - return; + if (this.resultItems && this.resultItems.length > 0 || (!text && this._state.isResults)) { + if (!text && !this.view.inputText.getValue()) { // remove empty cells highlighting when we open panel again + this._state.noSearchEmptyCells = true; + this.onQuerySearch(); + return; + } + if (!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() || + this._state.matchCase && text === this.view.inputText.getValue()) { // show old results + return; + } } if (text) { this.view.setFindText(text); - } else if (text !== undefined) { // panel was opened from empty searchbar, clear to start new search + } else if (fromEmptySearchBar) { // panel was opened from empty searchbar this.view.setFindText(''); - this._state.searchText = undefined; + if (!this._state.isResults) { + this._state.searchText = undefined; + } } this.hideResults(); - if (this._state.searchText !== undefined && text === this._state.searchText) { // search was made + if (this._state.searchText !== undefined && text && text === this._state.searchText && this._state.isResults) { // search was made this.api.asc_StartTextAroundSearch(); - } else if (this._state.searchText !== undefined) { // search wasn't made - this.onInputSearchChange(text); + } else if (this._state.searchText) { // search wasn't made + this._state.searchText = text; + this.onQuerySearch(); } else { this.resultItems = []; this.view.clearResultsNumber();