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:
parent
ad96c6f838
commit
97d2b5df15
@ -429,9 +429,8 @@ RED.search = (function() {
|
||||
}
|
||||
searchHistory.unshift(searchVal);
|
||||
$("#red-ui-view-searchtools-search").data("term", searchVal);
|
||||
hide();
|
||||
activeResults = Object.assign([], currentResults);
|
||||
updateSearchToolbar();
|
||||
hide(null, activeResults.length > 0);
|
||||
RED.view.reveal(node.id);
|
||||
}
|
||||
|
||||
@ -452,6 +451,7 @@ RED.search = (function() {
|
||||
const n = activeResults[currentIndex];
|
||||
if (n && n.node && n.node.id) {
|
||||
RED.view.reveal(n.node.id);
|
||||
$("#red-ui-view-searchtools-prev").trigger("focus");
|
||||
}
|
||||
updateSearchToolbar();
|
||||
}
|
||||
@ -472,6 +472,7 @@ RED.search = (function() {
|
||||
const n = activeResults[currentIndex];
|
||||
if (n && n.node && n.node.id) {
|
||||
RED.view.reveal(n.node.id);
|
||||
$("#red-ui-view-searchtools-next").trigger("focus");
|
||||
}
|
||||
updateSearchToolbar();
|
||||
}
|
||||
@ -505,7 +506,7 @@ RED.search = (function() {
|
||||
searchInput.trigger("focus");
|
||||
}
|
||||
|
||||
function hide() {
|
||||
function hide(el, keepSearchToolbar) {
|
||||
if (visible) {
|
||||
visible = false;
|
||||
$("#red-ui-header-shade").hide();
|
||||
@ -519,27 +520,34 @@ RED.search = (function() {
|
||||
});
|
||||
}
|
||||
RED.events.emit("search:close");
|
||||
if (previousActiveElement) {
|
||||
if (previousActiveElement && (!keepSearchToolbar || !activeResults.length)) {
|
||||
$(previousActiveElement).trigger("focus");
|
||||
}
|
||||
previousActiveElement = null;
|
||||
}
|
||||
if(!keepSearchToolbar) {
|
||||
clearActiveSearch();
|
||||
}
|
||||
updateSearchToolbar();
|
||||
if(keepSearchToolbar && activeResults.length) {
|
||||
$("#red-ui-view-searchtools-next").trigger("focus");
|
||||
}
|
||||
}
|
||||
function updateSearchToolbar() {
|
||||
if(!disabled && currentIndex >= 0 && activeResults && activeResults.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) + "..."
|
||||
if (term.length > 16) {
|
||||
term = term.substring(0, 12) + "..."
|
||||
}
|
||||
const i18nSearchCounterData = {
|
||||
term : term,
|
||||
result: (currentIndex+1),
|
||||
term: term,
|
||||
result: (currentIndex + 1),
|
||||
count: activeResults.length
|
||||
}
|
||||
$("#red-ui-view-searchtools-counter").text(RED._('actions.search-counter', i18nSearchCounterData));
|
||||
$("#view-search-tools > :not(:first-child)").show(); //show other tools
|
||||
} else {
|
||||
clearActiveSearch();
|
||||
$("#view-search-tools > :not(:first-child)").hide(); //hide all but search button
|
||||
}
|
||||
}
|
||||
@ -564,6 +572,11 @@ RED.search = (function() {
|
||||
addItemToIndex(item);
|
||||
}
|
||||
|
||||
function clearActiveSearch() {
|
||||
activeResults = [];
|
||||
currentIndex = 0;
|
||||
$("#red-ui-view-searchtools-search").data("term", "");
|
||||
}
|
||||
|
||||
function init() {
|
||||
RED.actions.add("core:search",show);
|
||||
@ -579,14 +592,18 @@ RED.search = (function() {
|
||||
|
||||
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-editor-shade").on('mousedown',hide);
|
||||
$("#red-ui-palette-shade").on('mousedown',hide);
|
||||
$("#red-ui-sidebar-shade").on('mousedown',hide);
|
||||
|
||||
$("#red-ui-view-searchtools-close").on("click", function close() {
|
||||
activeResults = [];
|
||||
$("#red-ui-view-searchtools-search").data("term", "");
|
||||
clearActiveSearch();
|
||||
updateSearchToolbar();
|
||||
});
|
||||
$("#red-ui-view-searchtools-close").trigger("click");
|
||||
|
Loading…
Reference in New Issue
Block a user