[DE PE SSE] Add results number in search bar

This commit is contained in:
JuliaSvinareva
2023-02-02 21:13:00 +03:00
parent a61b22e8e3
commit b520031caf
8 changed files with 79 additions and 10 deletions

View File

@ -62,7 +62,10 @@ define([
this.template = [
'<div class="box">',
'<input type="text" id="search-bar-text" class="input-field form-control" maxlength="255" placeholder="'+this.textFind+'" autocomplete="off">',
'<div class="search-input-group">',
'<input type="text" id="search-bar-text" class="input-field form-control" maxlength="255" placeholder="'+this.textFind+'" autocomplete="off">',
'<div id="search-bar-results">0/0</div>',
'</div>',
'<div class="tools">',
'<div id="search-bar-back"></div>',
'<div id="search-bar-next"></div>',
@ -128,9 +131,14 @@ define([
this.hide();
}, this))
this.searchResults = $('#search-bar-results');
this.on('animate:before', _.bind(this.focus, this));
Common.NotificationCenter.on('search:updateresults', _.bind(this.disableNavButtons, this));
Common.NotificationCenter.on('search:updateresults', _.bind(function (resultNumber, allResults) {
this.disableNavButtons(resultNumber, allResults);
this.updateResultsNumber(resultNumber, allResults);
}, this));
return this;
},
@ -192,6 +200,12 @@ define([
this.btnNext.setDisabled(disable);
},
updateResultsNumber: function (current, all) {
this.searchResults.text(!all || (this.inputSearch.val() === '' && !window.SSE) ? '0/0' :
(Common.UI.isRTL() ? all + '/' + (current + 1) : current + 1 + '/' + all));
this.inputSearch.css(Common.UI.isRTL() ? 'padding-left' : 'padding-right', this.searchResults.outerWidth() + 'px');
},
textFind: 'Find',
tipPreviousResult: 'Previous result',
tipNextResult: 'Next result',

View File

@ -87,8 +87,25 @@
.box {
padding: 15px;
display: flex;
input[type=text] {
width: 192px;
.search-input-group {
display: flex;
position: relative;
input[type=text] {
width: 192px;
}
#search-bar-results {
position: absolute;
right: 0;
height: 100%;
line-height: 22px;
padding: 0 4px;
color: @text-secondary-ie;
color: @text-secondary;
.rtl & {
right: auto;
left: 0;
}
}
}
.tools {
display: flex;
@ -97,6 +114,14 @@
margin-left: 5px;
&:first-of-type {
margin-left: 7px;
.rtl & {
margin-left: 0;
margin-right: 7px;
}
}
.rtl & {
margin-left: 0;
margin-right: 5px;
}
}
}

View File

@ -186,6 +186,8 @@ define([
me.view.disableReplaceButtons(true);
clearInterval(me.searchTimer);
me.searchTimer = undefined;
Common.NotificationCenter.trigger('search:updateresults');
}
}, 10);
}
@ -211,6 +213,8 @@ define([
this._state.currentResult = 0;
this._state.resultsNumber = 0;
this.view.disableNavButtons();
Common.NotificationCenter.trigger('search:updateresults');
return false;
}
if (update && this.view.$el.is(':visible') && this.view.$resultsContainer.find('.many-results').length === 0) {
@ -485,6 +489,10 @@ define([
return this._state.searchText;
},
getResultsNumber: function () {
return [this._state.currentResult, this._state.resultsNumber];
},
notcriticalErrorTitle: 'Warning',
warnReplaceString: '{0} is not a valid special character for the Replace With box.',
textReplaceSuccess: 'Search has been done. {0} occurrences have been replaced',

View File

@ -311,8 +311,11 @@ define([
}, this));
}
if (this.header.btnSearch.pressed) {
var selectedText = this.api.asc_GetSelectedText();
this.searchBar.show(selectedText && selectedText.trim() || this.getApplication().getController('Search').getSearchText());
var selectedText = this.api.asc_GetSelectedText(),
searchController = this.getApplication().getController('Search'),
resultsNumber = searchController.getResultsNumber();
this.searchBar.show(selectedText && selectedText.trim() || searchController.getSearchText());
this.searchBar.updateResultsNumber(resultsNumber[0], resultsNumber[1]);
} else {
this.searchBar.hide();
}

View File

@ -183,6 +183,8 @@ define([
me.view.disableReplaceButtons(true);
clearInterval(me.searchTimer);
me.searchTimer = undefined;
Common.NotificationCenter.trigger('search:updateresults');
}
}, 10);
}
@ -208,6 +210,8 @@ define([
this._state.currentResult = 0;
this._state.resultsNumber = 0;
this.view.disableNavButtons();
Common.NotificationCenter.trigger('search:updateresults');
return false;
}
@ -435,6 +439,10 @@ define([
return this._state.searchText;
},
getResultsNumber: function () {
return [this._state.currentResult, this._state.resultsNumber];
},
notcriticalErrorTitle: 'Warning',
warnReplaceString: '{0} is not a valid special character for the Replace With box.',
textReplaceSuccess: 'Search has been done. {0} occurrences have been replaced',

View File

@ -372,8 +372,11 @@ define([
}, this));
}
if (this.header.btnSearch.pressed) {
var selectedText = this.api.asc_GetSelectedText();
this.searchBar.show(selectedText && selectedText.trim() || this.getApplication().getController('Search').getSearchText());
var selectedText = this.api.asc_GetSelectedText(),
searchController = this.getApplication().getController('Search'),
resultsNumber = searchController.getResultsNumber();
this.searchBar.show(selectedText && selectedText.trim() || searchController.getSearchText());
this.searchBar.updateResultsNumber(resultsNumber[0], resultsNumber[1]);
} else {
this.searchBar.hide();
}

View File

@ -292,6 +292,7 @@ define([
} else {
this.removeResultItems();
}
Common.NotificationCenter.trigger('search:updateresults');
return false;
}
this._state.isResults = true;
@ -605,6 +606,10 @@ define([
return this._state.searchText;
},
getResultsNumber: function () {
return [this._state.currentResult, this._state.resultsNumber];
},
onApiUpdateSearchElem: function (data) { // [id, sheet, name, cell, value, formula]
if (this.resultItems && this.resultItems.length > 0) {
var me = this;

View File

@ -338,8 +338,11 @@ define([
}, this));
}
if (this.header.btnSearch.pressed) {
var selectedText = this.api.asc_GetSelectedText();
this.searchBar.show(selectedText && selectedText.trim() || this.getApplication().getController('Search').getSearchText());
var selectedText = this.api.asc_GetSelectedText(),
searchController = this.getApplication().getController('Search'),
resultsNumber = searchController.getResultsNumber();
this.searchBar.show(selectedText && selectedText.trim() || searchController.getSearchText());
this.searchBar.updateResultsNumber(resultsNumber[0], resultsNumber[1]);
} else {
this.searchBar.hide();
}