Merge pull request #1945 from ONLYOFFICE/fix/fix-bugs
[DE PE] Disable searching for whole words when there are punctuation …
This commit is contained in:
commit
ae4813a5d8
|
@ -118,6 +118,29 @@ define([
|
||||||
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
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) {
|
onChangeSearchOption: function (option, checked) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'case-sensitive':
|
case 'case-sensitive':
|
||||||
|
@ -138,6 +161,7 @@ define([
|
||||||
onSearchNext: function (type, text, e) {
|
onSearchNext: function (type, text, e) {
|
||||||
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.checkPunctuation(text);
|
||||||
this._state.searchText = text;
|
this._state.searchText = text;
|
||||||
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
|
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
|
||||||
}
|
}
|
||||||
|
@ -152,6 +176,7 @@ define([
|
||||||
this.searchTimer = setInterval(function(){
|
this.searchTimer = setInterval(function(){
|
||||||
if ((new Date()) - me._lastInputChange < 400) return;
|
if ((new Date()) - me._lastInputChange < 400) return;
|
||||||
|
|
||||||
|
me.checkPunctuation(me._state.newSearchText);
|
||||||
me._state.searchText = me._state.newSearchText;
|
me._state.searchText = me._state.newSearchText;
|
||||||
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
||||||
me.view.updateResultsNumber('no-results');
|
me.view.updateResultsNumber('no-results');
|
||||||
|
@ -370,6 +395,7 @@ define([
|
||||||
|
|
||||||
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);
|
||||||
|
this.checkPunctuation(text);
|
||||||
if (this.resultItems && this.resultItems.length > 0 &&
|
if (this.resultItems && this.resultItems.length > 0 &&
|
||||||
(!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() ||
|
(!this._state.matchCase && text && text.toLowerCase() === this.view.inputText.getValue().toLowerCase() ||
|
||||||
this._state.matchCase && text === this.view.inputText.getValue())) { // show old results
|
this._state.matchCase && text === this.view.inputText.getValue())) { // show old results
|
||||||
|
|
|
@ -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) {
|
onSearchNext: function (type, text, e) {
|
||||||
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.checkPunctuation(text);
|
||||||
this._state.searchText = text;
|
this._state.searchText = text;
|
||||||
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
|
this.onQuerySearch(type, !(this.searchTimer || isReturnKey));
|
||||||
}
|
}
|
||||||
|
@ -149,6 +173,7 @@ define([
|
||||||
this.searchTimer = setInterval(function(){
|
this.searchTimer = setInterval(function(){
|
||||||
if ((new Date()) - me._lastInputChange < 400) return;
|
if ((new Date()) - me._lastInputChange < 400) return;
|
||||||
|
|
||||||
|
me.checkPunctuation(me._state.newSearchText);
|
||||||
me._state.searchText = me._state.newSearchText;
|
me._state.searchText = me._state.newSearchText;
|
||||||
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
if (!(me._state.newSearchText !== '' && me.onQuerySearch()) && me._state.newSearchText === '') {
|
||||||
me.view.updateResultsNumber('no-results');
|
me.view.updateResultsNumber('no-results');
|
||||||
|
@ -336,6 +361,7 @@ define([
|
||||||
|
|
||||||
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);
|
||||||
|
this.checkPunctuation(text);
|
||||||
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 (text !== undefined) { // panel was opened from empty searchbar, clear to start new search
|
||||||
|
|
Loading…
Reference in a new issue