[DE PE] Disable searching for whole words when there are punctuation marks

This commit is contained in:
JuliaSvinareva 2022-09-06 17:04:56 +03:00
parent 904e8ea272
commit 7af5548157
2 changed files with 52 additions and 0 deletions

View file

@ -118,6 +118,29 @@ define([
this.view : Backbone.Controller.prototype.getView.call(this, name);
},
checkPunctuation: function (text) {
if (!!text) {
var isPunctuation = false;
for (var l = 0; l < text.length; l++) {
var charCode = text.charCodeAt(l),
char = text.charAt(l);
if (AscCommon.g_aPunctuation[charCode] !== undefined || char.trim() === '') {
isPunctuation = true;
break;
}
}
if (isPunctuation) {
if (this._state.matchWord) {
this.view.chMatchWord.setValue(false, true);
this._state.matchWord = false;
}
this.view.chMatchWord.setDisabled(true);
} else if (this.view.chMatchWord.isDisabled()) {
this.view.chMatchWord.setDisabled(false);
}
}
},
onChangeSearchOption: function (option, checked) {
switch (option) {
case 'case-sensitive':
@ -138,6 +161,7 @@ define([
onSearchNext: function (type, text, e) {
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
this.checkPunctuation(text);
this._state.searchText = text;
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
}
@ -152,6 +176,7 @@ define([
this.searchTimer = setInterval(function(){
if ((new Date()) - me._lastInputChange < 400) return;
me.checkPunctuation(me._state.newSearchText);
me._state.searchText = me._state.newSearchText;
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
me.view.updateResultsNumber('no-results');
@ -370,6 +395,7 @@ define([
var selectedText = this.api.asc_GetSelectedText(),
text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText);
this.checkPunctuation(text);
if (this.resultItems && this.resultItems.length > 0 &&
(!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() ||
this._state.matchCase && text === this.view.inputText.getValue())) { // show old results

View file

@ -132,9 +132,33 @@ define([
}
},
checkPunctuation: function (text) {
if (!!text) {
var isPunctuation = false;
for (var l = 0; l < text.length; l++) {
var charCode = text.charCodeAt(l),
char = text.charAt(l);
if (AscCommon.g_aPunctuation[charCode] !== undefined || char.trim() === '') {
isPunctuation = true;
break;
}
}
if (isPunctuation) {
if (this._state.matchWord) {
this.view.chMatchWord.setValue(false, true);
this._state.matchWord = false;
}
this.view.chMatchWord.setDisabled(true);
} else if (this.view.chMatchWord.isDisabled()) {
this.view.chMatchWord.setDisabled(false);
}
}
},
onSearchNext: function (type, text, e) {
var isReturnKey = type === 'keydown' && e.keyCode === Common.UI.Keys.RETURN;
if (text && text.length > 0 && (isReturnKey || type !== 'keydown')) {
this.checkPunctuation(text);
this._state.searchText = text;
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
}
@ -149,6 +173,7 @@ define([
this.searchTimer = setInterval(function(){
if ((new Date()) - me._lastInputChange < 400) return;
me.checkPunctuation(me._state.newSearchText);
me._state.searchText = me._state.newSearchText;
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
me.view.updateResultsNumber('no-results');
@ -336,6 +361,7 @@ define([
var selectedText = this.api.asc_GetSelectedText(),
text = typeof findText === 'string' ? findText : (selectedText && selectedText.trim() || this._state.searchText);
this.checkPunctuation(text);
if (text) {
this.view.setFindText(text);
} else if (text !== undefined) { // panel was opened from empty searchbar, clear to start new search