From cc0933eee4c17a24ea45884579915ebf2e9b3fc7 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 11 Jun 2019 22:43:01 +0100 Subject: [PATCH] Rename commandPrompt to actionList --- Gruntfile.js | 2 +- .../editor-client/locales/en-US/editor.json | 6 +- .../editor-client/src/js/keymap.json | 4 +- .../@node-red/editor-client/src/js/red.js | 3 +- .../js/ui/{commandPrompt.js => actionList.js} | 128 ++++++++---------- .../editor-client/src/js/ui/clipboard.js | 4 +- .../src/js/ui/common/editableList.js | 9 ++ .../editor-client/src/js/ui/search.js | 4 +- .../editor-client/src/sass/search.scss | 4 +- 9 files changed, 84 insertions(+), 80 deletions(-) rename packages/node_modules/@node-red/editor-client/src/js/ui/{commandPrompt.js => actionList.js} (65%) diff --git a/Gruntfile.js b/Gruntfile.js index f6fb3e19a..8b7b85a25 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -169,7 +169,7 @@ module.exports = function(grunt) { "packages/node_modules/@node-red/editor-client/src/js/ui/library.js", "packages/node_modules/@node-red/editor-client/src/js/ui/notifications.js", "packages/node_modules/@node-red/editor-client/src/js/ui/search.js", - "packages/node_modules/@node-red/editor-client/src/js/ui/commandPrompt.js", + "packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js", "packages/node_modules/@node-red/editor-client/src/js/ui/typeSearch.js", "packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js", "packages/node_modules/@node-red/editor-client/src/js/ui/userSettings.js", diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index a92de4304..9a53a870c 100755 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -351,7 +351,8 @@ "pasteNode": "Paste nodes", "undoChange": "Undo the last change performed", "searchBox": "Open search box", - "managePalette": "Manage palette" + "managePalette": "Manage palette", + "actionList":"Action list" }, "library": { "library": "Library", @@ -710,8 +711,7 @@ }, "search": { "empty": "No matches found", - "addNode": "add a node...", - "actions": "search available actions" + "addNode": "add a node..." }, "expressionEditor": { "functions": "Functions", diff --git a/packages/node_modules/@node-red/editor-client/src/js/keymap.json b/packages/node_modules/@node-red/editor-client/src/js/keymap.json index db7c4f77d..2db2d4836 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/keymap.json +++ b/packages/node_modules/@node-red/editor-client/src/js/keymap.json @@ -1,6 +1,6 @@ { "*": { - "ctrl-shift-p":"core:manage-palette", + "alt-shift-p":"core:manage-palette", "ctrl-f": "core:search", "ctrl-shift-f": "core:list-flows", "ctrl-=": "core:zoom-in", @@ -23,7 +23,7 @@ "ctrl-alt-o": "core:open-project", "ctrl-g v": "core:show-version-control-tab", "ctrl-shift-l": "core:show-event-log", - "alt-shift-p":"core:show-command-prompt" + "ctrl-shift-p":"core:show-action-list" }, "red-ui-sidebar-node-config": { "backspace": "core:delete-config-selection", diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index d8962c44a..715da7784 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -451,6 +451,7 @@ var RED = (function() { {id:"menu-item-palette",label:RED._("menu.label.palette.show"),toggle:true,onselect:"core:toggle-palette", selected: true}, {id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:true,onselect:"core:toggle-sidebar", selected: true}, {id:"menu-item-event-log",label:RED._("eventLog.title"),onselect:"core:show-event-log"}, + {id:"menu-item-action-list",label:RED._("keyboard.actionList"),onselect:"core:show-action-list"}, null ]}); menuOptions.push(null); @@ -521,7 +522,7 @@ var RED = (function() { RED.subflow.init(); RED.clipboard.init(); RED.search.init(); - RED.commandPrompt.init(); + RED.actionList.init(); RED.editor.init(); RED.diff.init(); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/commandPrompt.js b/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js similarity index 65% rename from packages/node_modules/@node-red/editor-client/src/js/ui/commandPrompt.js rename to packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js index 733be9aab..d3155051b 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/commandPrompt.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/actionList.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -RED.commandPrompt = (function() { +RED.actionList = (function() { var disabled = false; var dialog = null; @@ -22,34 +22,7 @@ RED.commandPrompt = (function() { var selected = -1; var visible = false; - var results = []; - - var scopes = {}; - - function search(val) { - scopes = {}; - results = []; - selected = -1; - val = val ||""; - searchResults.editableList('empty'); - - var actions = RED.actions.list(); - actions.sort(function(A,B) { - return A.id.localeCompare(B.id); - }); - - val = val.trim().toLowerCase(); - - actions.forEach(function(action) { - action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()}); - if (val !== "" && action.label.toLowerCase().indexOf(val) === -1) { - return; - } - results.push(action); - searchResults.editableList('addItem',action) - }) - - } + var filterTerm = ""; function ensureSelectedIsVisible() { var selectedEntry = searchResults.find("li.selected"); @@ -68,48 +41,50 @@ RED.commandPrompt = (function() { } function createDialog() { - dialog = $("
",{id:"red-ui-commandPrompt",class:"red-ui-search"}).appendTo("#red-ui-main-container"); + dialog = $("
",{id:"red-ui-actionList",class:"red-ui-search"}).appendTo("#red-ui-main-container"); var searchDiv = $("
",{class:"red-ui-search-container"}).appendTo(dialog); - searchInput = $('').appendTo(searchDiv).searchBox({ - delay: 200, + searchInput = $('').appendTo(searchDiv).searchBox({ change: function() { - search($(this).val()); + filterTerm = $(this).val(); + searchResults.editableList('filter'); + searchResults.find("li.selected").removeClass("selected"); } }); searchInput.on('keydown',function(evt) { - var children; - if (results.length > 0) { - if (evt.keyCode === 40) { - // Down - children = searchResults.children(); - if (selected < children.length-1) { - if (selected > -1) { - $(children[selected]).removeClass('selected'); - } - selected++; + var selectedChild; + if (evt.keyCode === 40) { + // Down + selectedChild = searchResults.find("li.selected"); + if (!selectedChild.length) { + var children = searchResults.children(":visible"); + if (children.length) { + $(children[0]).addClass('selected'); + RED.a = children[0]; } - $(children[selected]).addClass('selected'); - ensureSelectedIsVisible(); - evt.preventDefault(); - } else if (evt.keyCode === 38) { - // Up - children = searchResults.children(); - if (selected > 0) { - if (selected < children.length) { - $(children[selected]).removeClass('selected'); - } - selected--; - } - $(children[selected]).addClass('selected'); - ensureSelectedIsVisible(); - evt.preventDefault(); - } else if (evt.keyCode === 13) { - // Enter - if (results.length > 0) { - selectCommand(results[Math.max(0,selected)]); + } else { + var nextChild = selectedChild.nextAll(":visible").first(); + if (nextChild.length) { + selectedChild.removeClass('selected'); + nextChild.addClass('selected'); } } + ensureSelectedIsVisible(); + evt.preventDefault(); + } else if (evt.keyCode === 38) { + // Up + selectedChild = searchResults.find("li.selected"); + var nextChild = selectedChild.prevAll(":visible").first(); + if (nextChild.length) { + selectedChild.removeClass('selected'); + nextChild.addClass('selected'); + } + ensureSelectedIsVisible(); + evt.preventDefault(); + } else if (evt.keyCode === 13) { + // Enter + selectedChild = searchResults.find("li.selected"); + selectCommand(searchResults.editableList('getItem',selectedChild)); } }); searchInput.i18n(); @@ -137,14 +112,22 @@ RED.commandPrompt = (function() { }); } }, - scrollOnAdd: false + scrollOnAdd: false, + filter: function(item) { + if (filterTerm !== "" && item.label.toLowerCase().indexOf(filterTerm) === -1) { + return false; + } + return true; + } }); } function selectCommand(command) { hide(); - RED.actions.invoke(command.id); + if (command) { + RED.actions.invoke(command.id); + } } function show(v) { @@ -163,8 +146,17 @@ RED.commandPrompt = (function() { } dialog.slideDown(300); searchInput.searchBox('value',v) - search(v); - RED.events.emit("commandPrompt:open"); + searchResults.editableList('empty'); + results = []; + var actions = RED.actions.list(); + actions.sort(function(A,B) { + return A.id.localeCompare(B.id); + }); + actions.forEach(function(action) { + action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()}); + searchResults.editableList('addItem',action) + }) + RED.events.emit("actionList:open"); visible = true; } searchInput.trigger("focus"); @@ -184,12 +176,12 @@ RED.commandPrompt = (function() { searchInput.searchBox('value',''); }); } - RED.events.emit("commandPrompt:close"); + RED.events.emit("actionList:close"); } } function init() { - RED.actions.add("core:show-command-prompt",show); + RED.actions.add("core:show-action-list",show); RED.events.on("editor:open",function() { disabled = true; }); RED.events.on("editor:close",function() { disabled = false; }); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js b/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js index 8c8d3a664..cdff62919 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js @@ -742,8 +742,8 @@ RED.clipboard = (function() { RED.events.on("editor:close",function() { disabled = false; }); RED.events.on("search:open",function() { disabled = true; }); RED.events.on("search:close",function() { disabled = false; }); - RED.events.on("commandPrompt:open",function() { disabled = true; }); - RED.events.on("commandPrompt:close",function() { disabled = false; }); + RED.events.on("actionList:open",function() { disabled = true; }); + RED.events.on("actionList:close",function() { disabled = false; }); RED.events.on("type-search:open",function() { disabled = true; }); RED.events.on("type-search:close",function() { disabled = false; }); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/editableList.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/editableList.js index ee0251951..d4fa53dfa 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/editableList.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/editableList.js @@ -323,6 +323,7 @@ }, empty: function() { this.element.empty(); + this.uiContainer.scrollTop(0); }, filter: function(filter) { if (filter !== undefined) { @@ -346,6 +347,14 @@ if (items.length > 0) { this.uiContainer.scrollTop(this.uiContainer.scrollTop()+items.position().top) } + }, + getItem: function(li) { + var el = li.find(".red-ui-editableList-item-content"); + if (el.length) { + return el.data('data'); + } else { + return null; + } } }); })(jQuery); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/search.js b/packages/node_modules/@node-red/editor-client/src/js/ui/search.js index 74072065a..dcb147de7 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/search.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/search.js @@ -296,8 +296,8 @@ RED.search = (function() { RED.events.on("editor:close",function() { disabled = false; }); RED.events.on("type-search:open",function() { disabled = true; }); RED.events.on("type-search:close",function() { disabled = false; }); - RED.events.on("commandPrompt:open",function() { disabled = true; }); - RED.events.on("commandPrompt:close",function() { disabled = false; }); + RED.events.on("actionList:open",function() { disabled = true; }); + RED.events.on("actionList:close",function() { disabled = false; }); diff --git a/packages/node_modules/@node-red/editor-client/src/sass/search.scss b/packages/node_modules/@node-red/editor-client/src/sass/search.scss index 2fd016508..0ec8b6525 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/search.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/search.scss @@ -198,7 +198,9 @@ color: $primary-text-color; } .red-ui-search-result-action-key { - float:right; + position: absolute; + top: 9px; + right: 0; margin-right: 10px; color: $tertiary-text-color; }