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