From 2098d2faaeb1658ef753eb9f4ac123698938480e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 27 Mar 2021 22:30:45 -0400 Subject: Hotkey arguments (#1565) * Update display * Move scope definitions * Update scopes button after changing action * Don't show menu if empty * Improve scope updating * Update style * Simplify * Add argument to settings * Update convertToNumber implementation * Add support for arguments * Pass argument to action handler * Update hotkey action definitions * Remove x3 options --- ext/js/display/display.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ext/js/display/display.js') diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 7cc3b437..b0805aca 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -115,10 +115,8 @@ class Display extends EventDispatcher { this._hotkeyHandler.registerActions([ ['close', () => { this._onHotkeyClose(); }], - ['nextEntry', () => { this._focusEntry(this._index + 1, true); }], - ['nextEntry3', () => { this._focusEntry(this._index + 3, true); }], - ['previousEntry', () => { this._focusEntry(this._index - 1, true); }], - ['previousEntry3', () => { this._focusEntry(this._index - 3, true); }], + ['nextEntry', this._onHotkeyActionMoveRelative.bind(this, 1)], + ['previousEntry', this._onHotkeyActionMoveRelative.bind(this, -1)], ['lastEntry', () => { this._focusEntry(this._definitions.length - 1, true); }], ['firstEntry', () => { this._focusEntry(0, true); }], ['historyBackward', () => { this._sourceTermView(); }], @@ -1825,6 +1823,13 @@ class Display extends EventDispatcher { this.close(); } + _onHotkeyActionMoveRelative(sign, argument) { + let count = Number.parseInt(argument, 10); + if (!Number.isFinite(count)) { count = 1; } + count = Math.max(0, Math.floor(count)); + this._focusEntry(this._index + count * sign, true); + } + _closeAllPopupMenus() { for (const popupMenu of PopupMenu.openMenus) { popupMenu.close(); -- cgit v1.2.3