mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 16:19:58 +02:00
Refactor ZenKeyboardShortcuts to include split view shortcuts and additional tab selection shortcuts
This commit is contained in:
parent
028c896112
commit
072a6099b4
1 changed files with 32 additions and 21 deletions
|
@ -30,17 +30,28 @@ const defaultKeyboardGroups = {
|
||||||
"zen-tab-new-shortcut",
|
"zen-tab-new-shortcut",
|
||||||
"zen-key-enter-full-screen",
|
"zen-key-enter-full-screen",
|
||||||
"zen-key-exit-full-screen",
|
"zen-key-exit-full-screen",
|
||||||
"zen-quit-app-shortcut"
|
"zen-quit-app-shortcut",
|
||||||
|
"id:key_selectTab1",
|
||||||
|
"id:key_selectTab2",
|
||||||
|
"id:key_selectTab3",
|
||||||
|
"id:key_selectTab4",
|
||||||
|
"id:key_selectTab5",
|
||||||
|
"id:key_selectTab6",
|
||||||
|
"id:key_selectTab7",
|
||||||
|
"id:key_selectTab8",
|
||||||
|
"id:key_selectLastTab",
|
||||||
],
|
],
|
||||||
navigation: [
|
navigation: [
|
||||||
"zen-key-go-back",
|
|
||||||
"zen-key-go-forward",
|
|
||||||
"zen-nav-back-shortcut-alt",
|
"zen-nav-back-shortcut-alt",
|
||||||
"zen-nav-fwd-shortcut-alt",
|
"zen-nav-fwd-shortcut-alt",
|
||||||
"zen-nav-reload-shortcut-2",
|
"zen-nav-reload-shortcut-2",
|
||||||
"zen-nav-reload-shortcut-skip-cache",
|
"zen-nav-reload-shortcut-skip-cache",
|
||||||
"zen-nav-reload-shortcut",
|
"zen-nav-reload-shortcut",
|
||||||
"zen-key-stop"
|
"zen-key-stop",
|
||||||
|
"id:goHome",
|
||||||
|
"id:key_gotoHistory",
|
||||||
|
"id:goBackKb",
|
||||||
|
"id:goForwardKb",
|
||||||
],
|
],
|
||||||
searchAndFind: [
|
searchAndFind: [
|
||||||
"zen-search-focus-shortcut",
|
"zen-search-focus-shortcut",
|
||||||
|
@ -263,13 +274,15 @@ class KeyShortcut {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getGroupFromL10nId(l10nId) {
|
static getGroupFromL10nId(l10nId, id) {
|
||||||
// Find inside defaultKeyboardGroups
|
// Find inside defaultKeyboardGroups
|
||||||
for (let group of Object.keys(defaultKeyboardGroups)) {
|
for (let group of Object.keys(defaultKeyboardGroups)) {
|
||||||
if (defaultKeyboardGroups[group].includes(l10nId)) {
|
for (let shortcut of defaultKeyboardGroups[group]) {
|
||||||
|
if (shortcut == l10nId || shortcut == "id:" + id) {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 'other';
|
return 'other';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +306,7 @@ class KeyShortcut {
|
||||||
key.getAttribute('id'),
|
key.getAttribute('id'),
|
||||||
key.getAttribute('key'),
|
key.getAttribute('key'),
|
||||||
key.getAttribute('keycode'),
|
key.getAttribute('keycode'),
|
||||||
KeyShortcut.getGroupFromL10nId(KeyShortcut.sanitizeL10nId(key.getAttribute('data-l10n-id'))),
|
KeyShortcut.getGroupFromL10nId(KeyShortcut.sanitizeL10nId(key.getAttribute('data-l10n-id')), key.getAttribute('id')),
|
||||||
KeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')),
|
KeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')),
|
||||||
key.getAttribute('command'),
|
key.getAttribute('command'),
|
||||||
key.getAttribute('data-l10n-id'),
|
key.getAttribute('data-l10n-id'),
|
||||||
|
@ -433,7 +446,6 @@ class KeyShortcut {
|
||||||
isUserEditable() {
|
isUserEditable() {
|
||||||
if (
|
if (
|
||||||
!this.#id ||
|
!this.#id ||
|
||||||
!this.#action ||
|
|
||||||
this.#internal ||
|
this.#internal ||
|
||||||
this.#reserved ||
|
this.#reserved ||
|
||||||
(this.#group == FIREFOX_SHORTCUTS_GROUP && this.#disabled)
|
(this.#group == FIREFOX_SHORTCUTS_GROUP && this.#disabled)
|
||||||
|
@ -462,10 +474,9 @@ class KeyShortcut {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ZenKeyboardShortcutsLoader {
|
class ZenKeyboardShortcutsLoader {
|
||||||
#shortcutsDirtyCache = {};
|
#shortcutsDirtyCache = undefined;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#shortcutsDirtyCache = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get shortcutsFile() {
|
get shortcutsFile() {
|
||||||
|
@ -477,8 +488,8 @@ class ZenKeyboardShortcutsLoader {
|
||||||
this.#shortcutsDirtyCache = data;
|
this.#shortcutsDirtyCache = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadObject(withoutCache = false) {
|
async loadObject() {
|
||||||
if (this.#shortcutsDirtyCache && !withoutCache) {
|
if (this.#shortcutsDirtyCache) {
|
||||||
return this.#shortcutsDirtyCache;
|
return this.#shortcutsDirtyCache;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -490,8 +501,8 @@ class ZenKeyboardShortcutsLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(withoutCache = false) {
|
async load() {
|
||||||
return (await this.loadObject(withoutCache))?.shortcuts;
|
return (await this.loadObject())?.shortcuts;
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove() {
|
async remove() {
|
||||||
|
@ -508,8 +519,9 @@ function zenGetDefaultShortcuts() {
|
||||||
let keySet = document.getElementById('mainKeyset');
|
let keySet = document.getElementById('mainKeyset');
|
||||||
let newShortcutList = [];
|
let newShortcutList = [];
|
||||||
|
|
||||||
// Firefox's standard keyset
|
// Firefox's standard keyset. Reverse order to keep the order of the keys
|
||||||
for (let key of keySet.children) {
|
for (let i = keySet.children.length - 1; i >= 0; i--) {
|
||||||
|
let key = keySet.children[i];
|
||||||
let parsed = KeyShortcut.parseFromXHTML(key);
|
let parsed = KeyShortcut.parseFromXHTML(key);
|
||||||
newShortcutList.push(parsed);
|
newShortcutList.push(parsed);
|
||||||
}
|
}
|
||||||
|
@ -713,7 +725,6 @@ var gZenKeyboardShortcutsManager = {
|
||||||
loader: new ZenKeyboardShortcutsLoader(),
|
loader: new ZenKeyboardShortcutsLoader(),
|
||||||
async init() {
|
async init() {
|
||||||
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
||||||
await SessionStore.promiseInitialized;
|
|
||||||
console.info('Zen CKS: Initializing shortcuts');
|
console.info('Zen CKS: Initializing shortcuts');
|
||||||
|
|
||||||
const loadedShortcuts = await this._loadSaved();
|
const loadedShortcuts = await this._loadSaved();
|
||||||
|
@ -727,9 +738,9 @@ var gZenKeyboardShortcutsManager = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async _loadSaved(withoutCache = false) {
|
async _loadSaved() {
|
||||||
var innerLoad = async() => {
|
var innerLoad = async() => {
|
||||||
let data = await this.loader.load(withoutCache);
|
let data = await this.loader.load();
|
||||||
if (!data || data.length == 0) {
|
if (!data || data.length == 0) {
|
||||||
return zenGetDefaultShortcuts();
|
return zenGetDefaultShortcuts();
|
||||||
}
|
}
|
||||||
|
@ -824,7 +835,7 @@ var gZenKeyboardShortcutsManager = {
|
||||||
let rv = [];
|
let rv = [];
|
||||||
|
|
||||||
if (!this._currentShortcutList) {
|
if (!this._currentShortcutList) {
|
||||||
this._currentShortcutList = await this._loadSaved(true);
|
this._currentShortcutList = await this._loadSaved();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let shortcut of this._currentShortcutList) {
|
for (let shortcut of this._currentShortcutList) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue