Merge pull request #1915 from ONLYOFFICE/fix/fix-bugs

Fix/fix bugs
This commit is contained in:
maxkadushkin 2022-08-26 11:54:36 +03:00 committed by GitHub
commit 937f4d3e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 16 deletions

View file

@ -145,6 +145,7 @@ define([
this.fireEvent('search:input', [text]); this.fireEvent('search:input', [text]);
} else { } else {
this.inputSearch.val(''); this.inputSearch.val('');
window.SSE && this.fireEvent('search:input', ['', true]);
} }
this.focus(); this.focus();

View file

@ -57,7 +57,14 @@ define([
'SearchBar': { 'SearchBar': {
'search:back': _.bind(this.onSearchNext, this, 'back'), 'search:back': _.bind(this.onSearchNext, this, 'back'),
'search:next': _.bind(this.onSearchNext, this, 'next'), '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) { if (this._state.searchText === text) {
Common.NotificationCenter.trigger('search:updateresults', this._state.currentResult, this._state.resultsNumber); Common.NotificationCenter.trigger('search:updateresults', this._state.currentResult, this._state.resultsNumber);
return; return;
@ -79,7 +86,7 @@ define([
'show': _.bind(this.onShowPanel, this), 'show': _.bind(this.onShowPanel, this),
'hide': _.bind(this.onHidePanel, this) 'hide': _.bind(this.onHidePanel, this)
}, },
'LeftMenu': { // TO DO 'LeftMenu': {
'search:aftershow': _.bind(this.onShowAfterSearch, this) 'search:aftershow': _.bind(this.onShowAfterSearch, this)
} }
}); });
@ -95,7 +102,10 @@ define([
lookInFormulas: true, lookInFormulas: true,
isValidSelectedRange: true, isValidSelectedRange: true,
lastSelectedItem: undefined, lastSelectedItem: undefined,
isContentChanged: false isContentChanged: false,
isResults: false,
noSearchEmptyCells: false,
isReturnPressed: false
}; };
}, },
@ -206,9 +216,14 @@ define([
this._state.searchText = text; this._state.searchText = text;
this.onQuerySearch(type); this.onQuerySearch(type);
} }
this._state.isReturnPressed = isReturnKey;
}, },
onInputSearchChange: function (text) { onInputSearchChange: function (text) {
if (!text && !this._state.isReturnPressed) {
this._state.noSearchEmptyCells = true;
}
this._state.isReturnPressed = false;
var me = this; var me = this;
if (this._state.searchText !== text) { if (this._state.searchText !== text) {
this._state.newSearchText = text; this._state.newSearchText = text;
@ -263,12 +278,22 @@ define([
options.asc_setLastSearchElem(this._state.lastSelectedItem); options.asc_setLastSearchElem(this._state.lastSelectedItem);
this.view.disableReplaceButtons(false); this.view.disableReplaceButtons(false);
this._state.isContentChanged = 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)) { 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; return false;
} }
this._state.isResults = true;
if (this.view.$el.is(':visible')) { if (this.view.$el.is(':visible')) {
this.api.asc_StartTextAroundSearch(); this.api.asc_StartTextAroundSearch();
} }
@ -349,6 +374,9 @@ define([
me.resultItems.splice(ind, 1); me.resultItems.splice(ind, 1);
} }
}); });
if (this.resultItems.length === 0) {
this.removeResultItems();
}
}, },
onUpdateSearchCurrent: function (current, all) { onUpdateSearchCurrent: function (current, all) {
@ -470,31 +498,40 @@ define([
}, },
onShowAfterSearch: function (findText) { onShowAfterSearch: function (findText) {
var viewport = this.getApplication().getController('Viewport'); var fromEmptySearchBar = findText === '',
viewport = this.getApplication().getController('Viewport');
if (viewport.isSearchBarVisible()) { if (viewport.isSearchBarVisible()) {
viewport.searchBar.hide(); viewport.searchBar.hide();
} }
var selectedText = this.api.asc_GetSelectedText(), var selectedText = this.api.asc_GetSelectedText(),
text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText); text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText);
if (this.resultItems && this.resultItems.length > 0 && if (this.resultItems && this.resultItems.length > 0 || (!text && this._state.isResults)) {
(!text && !this.view.inputText.getValue() || if (!text && !this.view.inputText.getValue()) { // remove empty cells highlighting when we open panel again
!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() || this._state.noSearchEmptyCells = true;
this._state.matchCase && text === this.view.inputText.getValue())) { // show old results this.onQuerySearch();
return; 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) { if (text) {
this.view.setFindText(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.view.setFindText('');
this._state.searchText = undefined; if (!this._state.isResults) {
this._state.searchText = undefined;
}
} }
this.hideResults(); 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(); this.api.asc_StartTextAroundSearch();
} else if (this._state.searchText !== undefined) { // search wasn't made } else if (this._state.searchText) { // search wasn't made
this.onInputSearchChange(text); this._state.searchText = text;
this.onQuerySearch();
} else { } else {
this.resultItems = []; this.resultItems = [];
this.view.clearResultsNumber(); this.view.clearResultsNumber();