From 32f05861e3523525abb5ab6c963fcd93105c7249 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 13 Apr 2018 14:30:36 +0300 Subject: [PATCH] FF: register hotkeys on startup; reset if empty --- js/prefs.js | 15 +++++++++++++++ options/options.js | 12 ++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/js/prefs.js b/js/prefs.js index 6bf8cd10..39881ce2 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -299,6 +299,21 @@ var prefs = new function Prefs() { }); }); + // register hotkeys + if (FIREFOX && (browser.commands || {}).update) { + const hotkeyPrefs = Object.keys(values).filter(k => k.startsWith('hotkey.')); + this.subscribe(hotkeyPrefs, (name, value) => { + try { + name = name.split('.')[1]; + if (value.trim()) { + browser.commands.update({name, shortcut: value}).catch(ignoreChromeError); + } else { + browser.commands.reset(name).catch(ignoreChromeError); + } + } catch (e) {} + }); + } + return; function doBroadcast() { diff --git a/options/options.js b/options/options.js index 0afae768..462600dc 100644 --- a/options/options.js +++ b/options/options.js @@ -159,6 +159,7 @@ function customizeHotkeys() { $create('td', $create('input', { id: 'hotkey.' + cmd, + type: 'search', //placeholder: t('helpKeyMapHotkey'), })), ]))), @@ -181,16 +182,15 @@ function customizeHotkeys() { }); function onInput() { - const hotkey = this.value.trim(); - if (!hotkey) { + const name = this.id.split('.')[1]; + const shortcut = this.value.trim(); + if (!shortcut) { + browser.commands.reset(name).catch(ignoreChromeError); this.setCustomValidity(''); return; } try { - browser.commands.update({ - name: this.id.split('.')[1], - shortcut: hotkey, - }).then( + browser.commands.update({name, shortcut}).then( () => this.setCustomValidity(''), err => this.setCustomValidity(err) );