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

close search toolbar on escape

This commit is contained in:
Steve-Mcl 2022-03-08 16:09:05 +00:00
parent ad96c6f838
commit 97d2b5df15

View File

@ -429,9 +429,8 @@ RED.search = (function() {
} }
searchHistory.unshift(searchVal); searchHistory.unshift(searchVal);
$("#red-ui-view-searchtools-search").data("term", searchVal); $("#red-ui-view-searchtools-search").data("term", searchVal);
hide();
activeResults = Object.assign([], currentResults); activeResults = Object.assign([], currentResults);
updateSearchToolbar(); hide(null, activeResults.length > 0);
RED.view.reveal(node.id); RED.view.reveal(node.id);
} }
@ -452,6 +451,7 @@ RED.search = (function() {
const n = activeResults[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);
$("#red-ui-view-searchtools-prev").trigger("focus");
} }
updateSearchToolbar(); updateSearchToolbar();
} }
@ -472,6 +472,7 @@ RED.search = (function() {
const n = activeResults[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);
$("#red-ui-view-searchtools-next").trigger("focus");
} }
updateSearchToolbar(); updateSearchToolbar();
} }
@ -505,7 +506,7 @@ RED.search = (function() {
searchInput.trigger("focus"); searchInput.trigger("focus");
} }
function hide() { function hide(el, keepSearchToolbar) {
if (visible) { if (visible) {
visible = false; visible = false;
$("#red-ui-header-shade").hide(); $("#red-ui-header-shade").hide();
@ -519,12 +520,18 @@ RED.search = (function() {
}); });
} }
RED.events.emit("search:close"); RED.events.emit("search:close");
if (previousActiveElement) { if (previousActiveElement && (!keepSearchToolbar || !activeResults.length)) {
$(previousActiveElement).trigger("focus"); $(previousActiveElement).trigger("focus");
}
previousActiveElement = null; previousActiveElement = null;
} }
if(!keepSearchToolbar) {
clearActiveSearch();
} }
updateSearchToolbar(); updateSearchToolbar();
if(keepSearchToolbar && activeResults.length) {
$("#red-ui-view-searchtools-next").trigger("focus");
}
} }
function updateSearchToolbar() { function updateSearchToolbar() {
if (!disabled && currentIndex >= 0 && activeResults && activeResults.length) { if (!disabled && currentIndex >= 0 && activeResults && activeResults.length) {
@ -540,6 +547,7 @@ RED.search = (function() {
$("#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
} else { } else {
clearActiveSearch();
$("#view-search-tools > :not(:first-child)").hide(); //hide all but search button $("#view-search-tools > :not(:first-child)").hide(); //hide all but search button
} }
} }
@ -564,6 +572,11 @@ RED.search = (function() {
addItemToIndex(item); addItemToIndex(item);
} }
function clearActiveSearch() {
activeResults = [];
currentIndex = 0;
$("#red-ui-view-searchtools-search").data("term", "");
}
function init() { function init() {
RED.actions.add("core:search",show); RED.actions.add("core:search",show);
@ -579,14 +592,18 @@ RED.search = (function() {
RED.keyboard.add("red-ui-search","escape",hide); RED.keyboard.add("red-ui-search","escape",hide);
RED.keyboard.add("view-search-tools","escape",function() {
clearActiveSearch();
updateSearchToolbar();
});
$("#red-ui-header-shade").on('mousedown',hide); $("#red-ui-header-shade").on('mousedown',hide);
$("#red-ui-editor-shade").on('mousedown',hide); $("#red-ui-editor-shade").on('mousedown',hide);
$("#red-ui-palette-shade").on('mousedown',hide); $("#red-ui-palette-shade").on('mousedown',hide);
$("#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() {
activeResults = []; clearActiveSearch();
$("#red-ui-view-searchtools-search").data("term", "");
updateSearchToolbar(); updateSearchToolbar();
}); });
$("#red-ui-view-searchtools-close").trigger("click"); $("#red-ui-view-searchtools-close").trigger("click");