aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-28 14:04:20 -0400
committerGitHub <noreply@github.com>2021-03-28 14:04:20 -0400
commitb4d6a5d3b4b83c7c3c7f835f775d3207a4b97067 (patch)
tree6039a7c190db6e4b8a4faeb5f8e74b5027bb82c4 /ext/js/pages/settings
parent98994d0b6529e665863bc9f6125eb3e116e0f9d5 (diff)
Toggle option hotkey (#1571)
* Set up toggleOption hotkey action settings * Update styles * Disable spell check and autocomplete * Add OptionToggleHotkeyHandler * Improve auto-close behaviour
Diffstat (limited to 'ext/js/pages/settings')
-rw-r--r--ext/js/pages/settings/keyboard-shortcuts-controller.js51
1 files changed, 46 insertions, 5 deletions
diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js
index 7dbf5aa2..aeff15b6 100644
--- a/ext/js/pages/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js
@@ -18,6 +18,7 @@
/* global
* DOMDataBinder
* KeyboardMouseInputField
+ * ObjectPropertyAccessor
*/
class KeyboardShortcutController {
@@ -50,7 +51,8 @@ class KeyboardShortcutController {
['playAudio', {scopes: new Set(['popup', 'search'])}],
['playAudioFromSource', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-audio-source', default: 'jpod101'}}],
['copyHostSelection', {scopes: new Set(['popup'])}],
- ['scanSelectedText', {scopes: new Set(['web'])}]
+ ['scanSelectedText', {scopes: new Set(['web'])}],
+ ['toggleOption', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-setting-path', default: ''}}]
]);
}
@@ -316,14 +318,13 @@ class KeyboardShortcutHotkeyEntry {
_onArgumentValueChange(template, e) {
const node = e.currentTarget;
- const value = this._getArgumentInputValue(node);
- let newValue = value;
+ let value = this._getArgumentInputValue(node);
switch (template) {
case 'hotkey-argument-move-offset':
- newValue = `${DOMDataBinder.convertToNumber(value, node)}`;
+ value = `${DOMDataBinder.convertToNumber(value, node)}`;
break;
}
- this._setArgument(newValue);
+ this._setArgument(value);
}
async _delete() {
@@ -467,6 +468,8 @@ class KeyboardShortcutHotkeyEntry {
this._setArgumentInputValue(node, value);
}
+ this._updateArgumentInputValidity();
+
await this._modifyProfileSettings([{
action: 'set',
path: `${this._basePath}.argument`,
@@ -540,6 +543,7 @@ class KeyboardShortcutHotkeyEntry {
if (inputNode !== null) {
this._setArgumentInputValue(inputNode, argument);
this._argumentInput = inputNode;
+ this._updateArgumentInputValidity();
this._argumentEventListeners.addEventListener(inputNode, 'change', this._onArgumentValueChange.bind(this, template), false);
}
this._argumentContainer.appendChild(node);
@@ -558,4 +562,41 @@ class KeyboardShortcutHotkeyEntry {
_setArgumentInputValue(node, value) {
node.value = value;
}
+
+ async _updateArgumentInputValidity() {
+ if (this._argumentInput === null) { return; }
+
+ let okay = true;
+ const {action, argument} = this._data;
+ const details = this._parent.getActionDetails(action);
+ const {argument: argumentDetails} = typeof details !== 'undefined' ? details : {};
+
+ if (typeof argumentDetails !== 'undefined') {
+ const {template} = argumentDetails;
+ switch (template) {
+ case 'hotkey-argument-setting-path':
+ okay = await this._isHotkeyArgumentSettingPathValid(argument);
+ break;
+ }
+ }
+
+ this._argumentInput.dataset.invalid = `${!okay}`;
+ }
+
+ async _isHotkeyArgumentSettingPathValid(path) {
+ if (path.length === 0) { return true; }
+
+ const options = await this._parent.settingsController.getOptions();
+ const accessor = new ObjectPropertyAccessor(options);
+ const pathArray = ObjectPropertyAccessor.getPathArray(path);
+ try {
+ const value = accessor.get(pathArray, pathArray.length);
+ if (typeof value === 'boolean') {
+ return true;
+ }
+ } catch (e) {
+ // NOP
+ }
+ return false;
+ }
}