1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

fix search counter glitch

This commit is contained in:
Steve-Mcl 2022-03-07 20:01:24 +00:00
parent 94e8fce40a
commit ad96c6f838

View File

@ -25,6 +25,7 @@ RED.search = (function() {
var searchHistory = [];
var index = {};
var currentResults = [];
var activeResults = [];
var currentIndex = 0;
var previousActiveElement;
@ -248,7 +249,6 @@ RED.search = (function() {
}
currentResults = search(value);
if (currentResults.length > 0) {
$("#red-ui-view-searchtools-search").data("term", value);
for (i=0;i<Math.min(currentResults.length,25);i++) {
searchResults.editableList('addItem',currentResults[i])
}
@ -427,47 +427,50 @@ RED.search = (function() {
if (existingIndex > -1) {
searchHistory.splice(existingIndex,1);
}
searchHistory.unshift(searchInput.val());
searchHistory.unshift(searchVal);
$("#red-ui-view-searchtools-search").data("term", searchVal);
hide();
activeResults = Object.assign([], currentResults);
updateSearchToolbar();
RED.view.reveal(node.id);
}
function revealPrev() {
if(disabled) {
if (disabled) {
updateSearchToolbar();
return;
}
if(!searchResults || !currentResults.length) {
if (!searchResults || !activeResults.length) {
show();
return;
}
if(currentIndex > 0) {
if (currentIndex > 0) {
currentIndex--;
} else {
currentIndex = currentResults.length-1;
currentIndex = activeResults.length - 1;
}
const n = currentResults[currentIndex];
if(n && n.node && n.node.id) {
const n = activeResults[currentIndex];
if (n && n.node && n.node.id) {
RED.view.reveal(n.node.id);
}
updateSearchToolbar();
}
function revealNext() {
if(disabled) {
if (disabled) {
updateSearchToolbar();
return;
}
if(!searchResults || !currentResults.length) {
if (!searchResults || !activeResults.length) {
show();
return;
}
if(currentIndex < currentResults.length-1) {
if (currentIndex < activeResults.length - 1) {
currentIndex++
} else {
currentIndex = 0;
}
const n = currentResults[currentIndex];
if(n && n.node && n.node.id) {
const n = activeResults[currentIndex];
if (n && n.node && n.node.id) {
RED.view.reveal(n.node.id);
}
updateSearchToolbar();
@ -524,8 +527,7 @@ RED.search = (function() {
updateSearchToolbar();
}
function updateSearchToolbar() {
if(!disabled && currentIndex >= 0 && currentResults && currentResults.length ) {
//$("#red-ui-view-searchtools-counter").text((currentIndex+1) + " of " + currentResults.length )
if(!disabled && currentIndex >= 0 && activeResults && activeResults.length ) {
let term = $("#red-ui-view-searchtools-search").data("term") || "";
if(term.length > 16) {
term = term.substring(0,12) + "..."
@ -533,7 +535,7 @@ RED.search = (function() {
const i18nSearchCounterData = {
term : term,
result: (currentIndex+1),
count: currentResults.length
count: activeResults.length
}
$("#red-ui-view-searchtools-counter").text(RED._('actions.search-counter', i18nSearchCounterData));
$("#view-search-tools > :not(:first-child)").show(); //show other tools
@ -583,7 +585,7 @@ RED.search = (function() {
$("#red-ui-sidebar-shade").on('mousedown',hide);
$("#red-ui-view-searchtools-close").on("click", function close() {
currentResults = [];
activeResults = [];
$("#red-ui-view-searchtools-search").data("term", "");
updateSearchToolbar();
});