[SSE] Search: fix actions after query search, refactoring

This commit is contained in:
JuliaSvinareva 2022-08-23 15:31:13 +03:00
parent 235af538e8
commit b7ee795365

View file

@ -168,12 +168,7 @@ define([
break; break;
} }
if (runSearch) { if (runSearch) {
this.hideResults(); this.onQuerySearch();
if (this.onQuerySearch()) {
this.searchTimer && clearInterval(this.searchTimer);
this.searchTimer = undefined;
this.api.asc_StartTextAroundSearch();
}
} }
}, },
@ -207,16 +202,7 @@ define([
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN; var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
if (isReturnKey || type !== 'keydown') { if (isReturnKey || type !== 'keydown') {
this._state.searchText = text; this._state.searchText = text;
if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) { this.onQuerySearch(type);
this.hideResults();
if (this.searchTimer) {
clearInterval(this.searchTimer);
this.searchTimer = undefined;
}
if (this.view.$el.is(':visible')) {
this.api.asc_StartTextAroundSearch();
}
}
} }
}, },
@ -229,25 +215,21 @@ define([
this.searchTimer = setInterval(function(){ this.searchTimer = setInterval(function(){
if ((new Date()) - me._lastInputChange < 400) return; if ((new Date()) - me._lastInputChange < 400) return;
me.hideResults();
me._state.searchText = me._state.newSearchText; me._state.searchText = me._state.newSearchText;
if (me.onQuerySearch()) { if (!me.onQuerySearch() && me._state.newSearchText === '') {
if (me.view.$el.is(':visible')) {
me.api.asc_StartTextAroundSearch();
}
} else if (me._state.newSearchText === '') {
me.view.updateResultsNumber('no-results'); me.view.updateResultsNumber('no-results');
me.view.disableNavButtons(); me.view.disableNavButtons();
Common.NotificationCenter.trigger('search:updateresults', undefined, 0); Common.NotificationCenter.trigger('search:updateresults', undefined, 0);
} }
clearInterval(me.searchTimer);
me.searchTimer = undefined;
}, 10); }, 10);
} }
} }
}, },
onQuerySearch: function (d, isNeedRecalc) { onQuerySearch: function (d, isNeedRecalc) {
this.searchTimer && clearInterval(this.searchTimer);
this.searchTimer = undefined;
var me = this; var me = this;
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range && !this._state.isValidSelectedRange) { if (this._state.withinSheet === Asc.c_oAscSearchBy.Range && !this._state.isValidSelectedRange) {
Common.UI.warning({ Common.UI.warning({
@ -261,7 +243,7 @@ define([
return; return;
} }
this._state.isContentChanged = false; this.hideResults();
var options = new Asc.asc_CFindOptions(); var options = new Asc.asc_CFindOptions();
options.asc_setFindWhat(this._state.searchText); options.asc_setFindWhat(this._state.searchText);
@ -275,16 +257,16 @@ define([
options.asc_setScanByRows(this._state.searchByRows); options.asc_setScanByRows(this._state.searchByRows);
options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); options.asc_setLookIn(this._state.lookInFormulas ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
options.asc_setNeedRecalc(isNeedRecalc); options.asc_setNeedRecalc(isNeedRecalc);
options.asc_setLastSearchElem(this._state.lastSelectedItem); this._state.isContentChanged && options.asc_setLastSearchElem(this._state.lastSelectedItem);
this._state.isContentChanged = false;
if (!this.api.asc_findText(options)) { if (!this.api.asc_findText(options)) {
this.resultItems = []; this.removeResultItems();
this.view.updateResultsNumber(undefined, 0);
this._state.currentResult = 0;
this._state.resultsNumber = 0;
this.view.disableNavButtons();
Common.NotificationCenter.trigger('search:updateresults', undefined, 0);
return false; return false;
} }
if (this.view.$el.is(':visible')) {
this.api.asc_StartTextAroundSearch();
}
return true; return true;
}, },
@ -301,7 +283,6 @@ define([
} }
options.asc_setScanByRows(this._state.searchByRows); options.asc_setScanByRows(this._state.searchByRows);
options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
options.asc_setLastSearchElem(this._state.lastSelectedItem);
options.asc_setIsReplaceAll(false); options.asc_setIsReplaceAll(false);
this.api.asc_replaceText(options); this.api.asc_replaceText(options);
@ -320,7 +301,6 @@ define([
} }
options.asc_setScanByRows(this._state.searchByRows); options.asc_setScanByRows(this._state.searchByRows);
options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value); options.asc_setLookIn(this._state.lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
options.asc_setLastSearchElem(this._state.lastSelectedItem);
options.asc_setIsReplaceAll(true); options.asc_setIsReplaceAll(true);
this.api.asc_replaceText(options); this.api.asc_replaceText(options);
@ -341,21 +321,7 @@ define([
}); });
} }
} else { } else {
var options = new Asc.asc_CFindOptions(); this.onQuerySearch();
options.asc_setFindWhat(this._state.searchText);
options.asc_setScanForward(true);
options.asc_setIsMatchCase(this._state.matchCase);
options.asc_setIsWholeCell(this._state.matchWord);
options.asc_setScanOnOnlySheet(this._state.withinSheet);
if (this._state.withinSheet === Asc.c_oAscSearchBy.Range) {
options.asc_setSpecificRange(this._state.selectedRange);
}
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();
}
} }
}, },
@ -573,12 +539,7 @@ define([
onActiveSheetChanged: function (index) { onActiveSheetChanged: function (index) {
if (this._state.isHighlightedResults && this._state.withinSheet === Asc.c_oAscSearchBy.Sheet) { if (this._state.isHighlightedResults && this._state.withinSheet === Asc.c_oAscSearchBy.Sheet) {
this.hideResults(); this.onQuerySearch(undefined, true);
if (this.onQuerySearch(undefined, true)) {
this.searchTimer && clearInterval(this.searchTimer);
this.searchTimer = undefined;
this.api.asc_StartTextAroundSearch();
}
} }
}, },