mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 04:29:58 +02:00
Refactor KeyShortcutModifiers to handle platform-specific key modifiers consistently
This commit is contained in:
parent
b991b42402
commit
1bc2cf53c8
1 changed files with 19 additions and 6 deletions
|
@ -290,7 +290,7 @@ class KeyShortcut {
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmpty() {
|
isEmpty() {
|
||||||
return !this.#key && !this.#keycode;
|
return !this.#key && !this.getRealKeycode();
|
||||||
}
|
}
|
||||||
|
|
||||||
static parseFromSaved(json) {
|
static parseFromSaved(json) {
|
||||||
|
@ -397,6 +397,13 @@ class KeyShortcut {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRealKeycode() {
|
||||||
|
if (this.#keycode === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.#keycode;
|
||||||
|
}
|
||||||
|
|
||||||
getID() {
|
getID() {
|
||||||
return this.#id;
|
return this.#id;
|
||||||
}
|
}
|
||||||
|
@ -418,15 +425,15 @@ class KeyShortcut {
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeyName() {
|
getKeyName() {
|
||||||
return this.#key;
|
return this.#key.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeyCode() {
|
getKeyCode() {
|
||||||
return this.#keycode;
|
return this.getRealKeycode();
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeyNameOrCode() {
|
getKeyNameOrCode() {
|
||||||
return this.#key ? this.#key : this.#keycode;
|
return this.#key ? this.getKeyName() : this.getKeyCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
isDisabled() {
|
isDisabled() {
|
||||||
|
@ -863,8 +870,13 @@ var gZenKeyboardShortcutsManager = {
|
||||||
if (key.getAttribute('internal') == 'true') {
|
if (key.getAttribute('internal') == 'true') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
key.setAttribute('disabled', 'true');
|
key.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the keyset, https://searchfox.org/mozilla-central/rev/a59018f9ff34170810b43e12bf6f09a1512de7ab/dom/events/GlobalKeyListener.cpp#478
|
||||||
|
const parent = element.parentElement;
|
||||||
|
element.remove();
|
||||||
|
parent.prepend(element);
|
||||||
},
|
},
|
||||||
|
|
||||||
_applyShortcuts() {
|
_applyShortcuts() {
|
||||||
|
@ -953,12 +965,13 @@ var gZenKeyboardShortcutsManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
checkForConflicts(shortcut, modifiers, id) {
|
checkForConflicts(shortcut, modifiers, id) {
|
||||||
|
const realShortcut = shortcut.toLowerCase();
|
||||||
for (let targetShortcut of this._currentShortcutList) {
|
for (let targetShortcut of this._currentShortcutList) {
|
||||||
if (targetShortcut.getID() == id) {
|
if (targetShortcut.getID() == id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetShortcut.getModifiers().equals(modifiers) && targetShortcut.getKeyNameOrCode() == shortcut) {
|
if (targetShortcut.getModifiers().equals(modifiers) && targetShortcut.getKeyNameOrCode()?.toLowerCase() == realShortcut) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue