From 3a54d00e2bddd9c4119879c5210cf16d3ac8f83a Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 24 Nov 2019 20:20:13 +0100 Subject: [PATCH] added shortcut filter in the options dialog --- .../dialogs/options/keyboard_shortcuts.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js index b00a374a1..0d9133eec 100644 --- a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js +++ b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js @@ -6,6 +6,10 @@ const TPL = `

Multiple shortcuts for the same action can be separated by comma.

+
+ +
+
@@ -27,6 +31,8 @@ const TPL = ` `; +let globActions; + export default class KeyboardShortcutsOptions { constructor() { $("#options-keyboard-shortcuts").html(TPL); @@ -36,6 +42,8 @@ export default class KeyboardShortcutsOptions { const $table = $("#keyboard-shortcut-table tbody"); server.get('keyboard-actions').then(actions => { + globActions = actions; + for (const action of actions) { const $tr = $(""); @@ -95,5 +103,39 @@ export default class KeyboardShortcutsOptions { } }); }); + + const $filter = $("#keyboard-shortcut-filter"); + + $filter.on('keyup', () => { + const filter = $filter.val().trim().toLowerCase(); + + $table.find("tr").each((i, el) => { + if (!filter) { + $(el).show(); + return; + } + + const actionName = $(el).find('input').attr('data-keyboard-action-name'); + + if (!actionName) { + $(el).hide(); + return; + } + + const action = globActions.find(act => act.actionName === actionName); + + if (!action) { + $(el).hide(); + return; + } + + $(el).toggle(!!( // !! to avoid toggle overloads with different behavior + action.actionName.toLowerCase().includes(filter) + || action.defaultShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter)) + || action.effectiveShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter)) + || (action.description && action.description.toLowerCase().includes(filter)) + )); + }); + }); } } \ No newline at end of file