summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-27 22:56:48 -0400
committerGitHub <noreply@github.com>2021-03-27 22:56:48 -0400
commit8fe0e5fdf5f2f205becbce7753bc384362c079b1 (patch)
tree0809b8ae790d0b518f95f3d92aa65b506790ed43
parent2098d2faaeb1658ef753eb9f4ac123698938480e (diff)
Add reset argument menu item (#1566)
-rw-r--r--ext/js/pages/settings/keyboard-shortcuts-controller.js34
-rw-r--r--ext/settings.html1
2 files changed, 32 insertions, 3 deletions
diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js
index 2f636541..a63430ee 100644
--- a/ext/js/pages/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js
@@ -227,6 +227,7 @@ class KeyboardShortcutHotkeyEntry {
this._eventListeners.addEventListener(scopesButton, 'menuOpen', this._onScopesMenuOpen.bind(this));
this._eventListeners.addEventListener(scopesButton, 'menuClose', this._onScopesMenuClose.bind(this));
+ this._eventListeners.addEventListener(menuButton, 'menuOpen', this._onMenuOpen.bind(this), false);
this._eventListeners.addEventListener(menuButton, 'menuClose', this._onMenuClose.bind(this), false);
this._eventListeners.addEventListener(this._actionSelect, 'change', this._onActionSelectChange.bind(this), false);
this._eventListeners.on(this._inputField, 'change', this._onInputFieldChange.bind(this));
@@ -244,6 +245,18 @@ class KeyboardShortcutHotkeyEntry {
// Private
+ _onMenuOpen(e) {
+ const {action} = this._data;
+
+ const {menu} = e.detail;
+ const resetArgument = menu.bodyNode.querySelector('.popup-menu-item[data-menu-action="resetArgument"]');
+
+ const details = this._parent.getActionDetails(action);
+ const argumentDetails = typeof details !== 'undefined' ? details.argument : void 0;
+
+ resetArgument.hidden = (typeof argumentDetails === 'undefined');
+ }
+
_onMenuClose(e) {
switch (e.detail.action) {
case 'delete':
@@ -255,6 +268,9 @@ class KeyboardShortcutHotkeyEntry {
case 'resetInput':
this._resetInput();
break;
+ case 'resetArgument':
+ this._resetArgument();
+ break;
}
}
@@ -306,9 +322,6 @@ class KeyboardShortcutHotkeyEntry {
newValue = `${DOMDataBinder.convertToNumber(value, node)}`;
break;
}
- if (value !== newValue) {
- this._setArgumentInputValue(node, newValue);
- }
this._setArgument(newValue);
}
@@ -369,6 +382,15 @@ class KeyboardShortcutHotkeyEntry {
this._inputField.setInput(key, modifiers);
}
+ async _resetArgument() {
+ const {action} = this._data;
+ const details = this._parent.getActionDetails(action);
+ const argumentDetails = typeof details !== 'undefined' ? details.argument : void 0;
+ let argumentDefault = typeof argumentDetails !== 'undefined' ? argumentDetails.default : void 0;
+ if (typeof argumentDefault !== 'string') { argumentDefault = ''; }
+ await this._setArgument(argumentDefault);
+ }
+
_getDefaultKeyAndModifiers(defaultHotkeys, action) {
for (const {action: action2, key, modifiers} of defaultHotkeys) {
if (action2 !== action) { continue; }
@@ -438,6 +460,12 @@ class KeyboardShortcutHotkeyEntry {
async _setArgument(value) {
this._data.argument = value;
+
+ const node = this._argumentInput;
+ if (node !== null && this._getArgumentInputValue(node) !== value) {
+ this._setArgumentInputValue(node, value);
+ }
+
await this._modifyProfileSettings([{
action: 'set',
path: `${this._basePath}.argument`,
diff --git a/ext/settings.html b/ext/settings.html
index 12526442..67510b99 100644
--- a/ext/settings.html
+++ b/ext/settings.html
@@ -3180,6 +3180,7 @@
<template id="hotkey-list-item-menu-template"><div class="popup-menu-container" tabindex="-1" role="dialog"><div class="popup-menu"><div class="popup-menu-body">
<button class="popup-menu-item" data-menu-action="clearInputs">Clear input</button>
<button class="popup-menu-item" data-menu-action="resetInput">Reset input</button>
+ <button class="popup-menu-item" data-menu-action="resetArgument">Reset argument</button>
<button class="popup-menu-item" data-menu-action="delete">Delete</button>
</div></div></div></template>