[DE PE] Search: show results when document is changed
This commit is contained in:
parent
d57f114315
commit
679ab93d2f
|
@ -90,7 +90,8 @@ define([
|
||||||
matchCase: false,
|
matchCase: false,
|
||||||
matchWord: false,
|
matchWord: false,
|
||||||
useRegExp: false,
|
useRegExp: false,
|
||||||
isHighlightedResults: false
|
isHighlightedResults: false,
|
||||||
|
isContentChanged: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -130,14 +131,7 @@ define([
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this._state.searchText) {
|
if (this._state.searchText) {
|
||||||
this.hideResults();
|
this.onQuerySearch();
|
||||||
if (this.onQuerySearch()) {
|
|
||||||
if (this.searchTimer) {
|
|
||||||
clearInterval(this.searchTimer);
|
|
||||||
this.searchTimer = undefined;
|
|
||||||
}
|
|
||||||
this.api.asc_StartTextAroundSearch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -145,16 +139,7 @@ define([
|
||||||
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
|
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
|
||||||
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
|
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
|
||||||
this._state.searchText = text;
|
this._state.searchText = text;
|
||||||
if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) {
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -167,26 +152,26 @@ 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._state.newSearchText !== '' && me.onQuerySearch()) {
|
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
||||||
if (me.view.$el.is(':visible')) {
|
|
||||||
me.api.asc_StartTextAroundSearch();
|
|
||||||
}
|
|
||||||
me.view.disableReplaceButtons(false);
|
|
||||||
} else if (me._state.newSearchText === '') {
|
|
||||||
me.view.updateResultsNumber('no-results');
|
me.view.updateResultsNumber('no-results');
|
||||||
me.view.disableNavButtons();
|
me.view.disableNavButtons();
|
||||||
me.view.disableReplaceButtons(true);
|
me.view.disableReplaceButtons(true);
|
||||||
|
clearInterval(me.searchTimer);
|
||||||
|
me.searchTimer = undefined;
|
||||||
}
|
}
|
||||||
clearInterval(me.searchTimer);
|
|
||||||
me.searchTimer = undefined;
|
|
||||||
}, 10);
|
}, 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();
|
var searchSettings = new AscCommon.CSearchSettings();
|
||||||
searchSettings.put_Text(this._state.searchText);
|
searchSettings.put_Text(this._state.searchText);
|
||||||
searchSettings.put_MatchCase(this._state.matchCase);
|
searchSettings.put_MatchCase(this._state.matchCase);
|
||||||
|
@ -200,6 +185,10 @@ define([
|
||||||
this.view.disableNavButtons();
|
this.view.disableNavButtons();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (update && this.view.$el.is(':visible')) {
|
||||||
|
this.api.asc_StartTextAroundSearch();
|
||||||
|
}
|
||||||
|
this.view.disableReplaceButtons(false);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -324,7 +313,8 @@ define([
|
||||||
onApiGetTextAroundSearch: function (data) {
|
onApiGetTextAroundSearch: function (data) {
|
||||||
if (this.view && this._state.isStartedAddingResults) {
|
if (this.view && this._state.isStartedAddingResults) {
|
||||||
if (data.length > 300 || !data.length) return;
|
if (data.length > 300 || !data.length) return;
|
||||||
var me = this;
|
var me = this,
|
||||||
|
selectedInd;
|
||||||
me.resultItems = [];
|
me.resultItems = [];
|
||||||
data.forEach(function (item, ind) {
|
data.forEach(function (item, ind) {
|
||||||
var el = document.createElement("div"),
|
var el = document.createElement("div"),
|
||||||
|
@ -334,17 +324,23 @@ define([
|
||||||
me.view.$resultsContainer.append(el);
|
me.view.$resultsContainer.append(el);
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
$(el).addClass('selected');
|
$(el).addClass('selected');
|
||||||
|
selectedInd = ind;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected};
|
var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected};
|
||||||
me.resultItems.push(resultItem);
|
me.resultItems.push(resultItem);
|
||||||
$(el).on('click', _.bind(function (el) {
|
$(el).on('click', _.bind(function (el) {
|
||||||
|
if (me._state.isContentChanged) {
|
||||||
|
me.onQuerySearch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
var id = item[0];
|
var id = item[0];
|
||||||
me.api.asc_SelectSearchElement(id);
|
me.api.asc_SelectSearchElement(id);
|
||||||
}, me));
|
}, me));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.view.$resultsContainer.show();
|
this.view.$resultsContainer.show();
|
||||||
|
this.scrollToSelectedResult(selectedInd);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -433,7 +429,11 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
onApiSearchEnd: function () {
|
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) {
|
onApiTextReplaced: function(found, replaced) {
|
||||||
|
|
|
@ -485,6 +485,8 @@
|
||||||
"Common.Views.SearchPanel.textWholeWords": "Whole words only",
|
"Common.Views.SearchPanel.textWholeWords": "Whole words only",
|
||||||
"Common.Views.SearchPanel.tipNextResult": "Next result",
|
"Common.Views.SearchPanel.tipNextResult": "Next result",
|
||||||
"Common.Views.SearchPanel.tipPreviousResult": "Previous 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.textLoading": "Loading",
|
||||||
"Common.Views.SelectFileDlg.textTitle": "Select Data Source",
|
"Common.Views.SelectFileDlg.textTitle": "Select Data Source",
|
||||||
"Common.Views.SignDialog.textBold": "Bold",
|
"Common.Views.SignDialog.textBold": "Bold",
|
||||||
|
|
|
@ -87,7 +87,8 @@ define([
|
||||||
searchText: '',
|
searchText: '',
|
||||||
matchCase: false,
|
matchCase: false,
|
||||||
matchWord: false,
|
matchWord: false,
|
||||||
useRegExp: false
|
useRegExp: false,
|
||||||
|
isContentChanged: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -127,14 +128,7 @@ define([
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this._state.searchText) {
|
if (this._state.searchText) {
|
||||||
this.hideResults();
|
this.onQuerySearch();
|
||||||
if (this.onQuerySearch()) {
|
|
||||||
if (this.searchTimer) {
|
|
||||||
clearInterval(this.searchTimer);
|
|
||||||
this.searchTimer = undefined;
|
|
||||||
}
|
|
||||||
this.api.asc_StartTextAroundSearch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -142,16 +136,7 @@ define([
|
||||||
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
|
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
|
||||||
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
|
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
|
||||||
this._state.searchText = text;
|
this._state.searchText = text;
|
||||||
if (this.onQuerySearch(type) && (this.searchTimer || isReturnKey)) {
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -164,26 +149,26 @@ 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._state.newSearchText !== '' && me.onQuerySearch()) {
|
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
||||||
if (me.view.$el.is(':visible')) {
|
|
||||||
me.api.asc_StartTextAroundSearch();
|
|
||||||
}
|
|
||||||
me.view.disableReplaceButtons(false);
|
|
||||||
} else if (me._state.newSearchText === '') {
|
|
||||||
me.view.updateResultsNumber('no-results');
|
me.view.updateResultsNumber('no-results');
|
||||||
me.view.disableNavButtons();
|
me.view.disableNavButtons();
|
||||||
me.view.disableReplaceButtons(true);
|
me.view.disableReplaceButtons(true);
|
||||||
|
clearInterval(me.searchTimer);
|
||||||
|
me.searchTimer = undefined;
|
||||||
}
|
}
|
||||||
clearInterval(me.searchTimer);
|
|
||||||
me.searchTimer = undefined;
|
|
||||||
}, 10);
|
}, 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();
|
var searchSettings = new AscCommon.CSearchSettings();
|
||||||
searchSettings.put_Text(this._state.searchText);
|
searchSettings.put_Text(this._state.searchText);
|
||||||
searchSettings.put_MatchCase(this._state.matchCase);
|
searchSettings.put_MatchCase(this._state.matchCase);
|
||||||
|
@ -197,6 +182,11 @@ define([
|
||||||
this.view.disableNavButtons();
|
this.view.disableNavButtons();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (update && this.view.$el.is(':visible')) {
|
||||||
|
this.api.asc_StartTextAroundSearch();
|
||||||
|
}
|
||||||
|
this.view.disableReplaceButtons(false);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -289,7 +279,8 @@ define([
|
||||||
onApiGetTextAroundSearch: function (data) {
|
onApiGetTextAroundSearch: function (data) {
|
||||||
if (this.view && this._state.isStartedAddingResults) {
|
if (this.view && this._state.isStartedAddingResults) {
|
||||||
if (data.length > 300 || !data.length) return;
|
if (data.length > 300 || !data.length) return;
|
||||||
var me = this;
|
var me = this,
|
||||||
|
selectedInd;
|
||||||
me.resultItems = [];
|
me.resultItems = [];
|
||||||
data.forEach(function (item, ind) {
|
data.forEach(function (item, ind) {
|
||||||
var el = document.createElement("div"),
|
var el = document.createElement("div"),
|
||||||
|
@ -299,17 +290,23 @@ define([
|
||||||
me.view.$resultsContainer.append(el);
|
me.view.$resultsContainer.append(el);
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
$(el).addClass('selected');
|
$(el).addClass('selected');
|
||||||
|
selectedInd = ind;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected};
|
var resultItem = {id: item[0], $el: $(el), el: el, selected: isSelected};
|
||||||
me.resultItems.push(resultItem);
|
me.resultItems.push(resultItem);
|
||||||
$(el).on('click', _.bind(function (el) {
|
$(el).on('click', _.bind(function (el) {
|
||||||
|
if (me._state.isContentChanged) {
|
||||||
|
me.onQuerySearch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
var id = item[0];
|
var id = item[0];
|
||||||
me.api.asc_SelectSearchElement(id);
|
me.api.asc_SelectSearchElement(id);
|
||||||
}, me));
|
}, me));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.view.$resultsContainer.show();
|
this.view.$resultsContainer.show();
|
||||||
|
this.scrollToSelectedResult(selectedInd);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -382,7 +379,11 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
onApiSearchEnd: function () {
|
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) {
|
onApiTextReplaced: function(found, replaced) {
|
||||||
|
|
|
@ -558,6 +558,8 @@
|
||||||
"Common.Views.SearchPanel.textWholeWords": "Whole words only",
|
"Common.Views.SearchPanel.textWholeWords": "Whole words only",
|
||||||
"Common.Views.SearchPanel.tipNextResult": "Next result",
|
"Common.Views.SearchPanel.tipNextResult": "Next result",
|
||||||
"Common.Views.SearchPanel.tipPreviousResult": "Previous 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.textLoading": "Loading",
|
||||||
"Common.Views.SelectFileDlg.textTitle": "Select Data Source",
|
"Common.Views.SelectFileDlg.textTitle": "Select Data Source",
|
||||||
"Common.Views.SignDialog.textBold": "Bold",
|
"Common.Views.SignDialog.textBold": "Bold",
|
||||||
|
|
Loading…
Reference in a new issue