mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 11:05:30 +02:00
refactor: Update ZenKeyboardShortcuts to include split view and workspace actions
This commit updates the ZenKeyboardShortcuts module to include new actions for split view and workspace management. It adds shortcuts for toggling between grid, vertical, and horizontal split views, as well as closing split views. Additionally, it introduces a shortcut for changing workspaces. The changes also include the addition of default shortcuts for the new actions and the initialization of shortcuts only on the browser page. Refactor other modules: - Remove unnecessary console.log statement in ZenThemeBuilder - Disable Firefox shortcuts in ZenKeyboardShortcuts - Remove redundant code in ZenViewSplitter Refactor ZenProfileDialogUI: - Improve profiles list and profile creation Refactor ZenWorkspaces.mjs: - Remove unnecessary code Refactor ZenViewSplitter.mjs: - Activate docShell for tab - Remove redundant code
This commit is contained in:
parent
3e1d38d907
commit
0ab7cda4d5
4 changed files with 117 additions and 9 deletions
5
.gitattributes
vendored
5
.gitattributes
vendored
|
@ -1 +1,4 @@
|
||||||
*.mjs linguist-language=TypeScript
|
*.mjs linguist-language=TypeScript
|
||||||
|
|
||||||
|
*-c.patch linguist-language=C++
|
||||||
|
*-cpp.patch linguist-language=C++
|
|
@ -3,6 +3,15 @@ const kZKSActions = {
|
||||||
// Note: If they start with "command:", it means that "command=" will be added to the key element,
|
// Note: If they start with "command:", it means that "command=" will be added to the key element,
|
||||||
// otherwise "oncommand=" will be added.
|
// otherwise "oncommand=" will be added.
|
||||||
|
|
||||||
|
// Split view actions
|
||||||
|
zenSplitViewGrid: ["gZenViewSplitter.toggleShortcut('grid')", "zen-split-view-grid", "split-view-action"],
|
||||||
|
zenSplitViewVertical: ["gZenViewSplitter.toggleShortcut('hsplit')", "zen-split-view-vertical", "split-view-action"],
|
||||||
|
zenSplitViewHorizontal: ["gZenViewSplitter.toggleShortcut('vsplit')", "zen-split-view-horizontal", "split-view-action"],
|
||||||
|
zenSplitViewClose: ["gZenViewSplitter.toggleShortcut('unsplit')", "zen-split-view-close", "split-view-action"],
|
||||||
|
|
||||||
|
// Workspace actions
|
||||||
|
zenChangeWorkspace: ["ZenWorkspaces.changeWorkspaceShortcut()", "zen-change-workspace", "workspace-action"],
|
||||||
|
|
||||||
// manage actions
|
// manage actions
|
||||||
openNewTab: ["command:cmd_newNavigatorTabNoEvent","open-new-tab", "tab-action"],
|
openNewTab: ["command:cmd_newNavigatorTabNoEvent","open-new-tab", "tab-action"],
|
||||||
closeTab: ["command:cmd_close", "close-tab", "tab-action"],
|
closeTab: ["command:cmd_close", "close-tab", "tab-action"],
|
||||||
|
@ -91,6 +100,25 @@ const kZKSActions = {
|
||||||
zenToggleWebPanels: ["gZenBrowserManagerSidebar.toggle()", "zen-toggle-web-panels", "sidebar-action"],
|
zenToggleWebPanels: ["gZenBrowserManagerSidebar.toggle()", "zen-toggle-web-panels", "sidebar-action"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const kZenDefaultShortcuts = {
|
||||||
|
// Split view actions
|
||||||
|
zenSplitViewGrid: "Ctrl+Alt+G",
|
||||||
|
zenSplitViewVertical: "Ctrl+Alt+V",
|
||||||
|
zenSplitViewHorizontal: "Ctrl+Alt+H",
|
||||||
|
zenSplitViewClose: "Ctrl+Alt+U",
|
||||||
|
|
||||||
|
// Workspace actions
|
||||||
|
zenChangeWorkspace: "Ctrl+Shift+E",
|
||||||
|
|
||||||
|
// Compact mode actions
|
||||||
|
zenToggleCompactMode: "Ctrl+Alt+C",
|
||||||
|
zenToggleCompactModeSidebar: "Ctrl+Alt+S",
|
||||||
|
zenToggleCompactModeToolbar: "Ctrl+Alt+T",
|
||||||
|
|
||||||
|
// manage actions
|
||||||
|
zenToggleWebPanels: "Ctrl+Shift+P",
|
||||||
|
};
|
||||||
|
|
||||||
// Section: ZenKeyboardShortcuts
|
// Section: ZenKeyboardShortcuts
|
||||||
|
|
||||||
const kZKSStorageKey = "zen.keyboard.shortcuts";
|
const kZKSStorageKey = "zen.keyboard.shortcuts";
|
||||||
|
@ -107,17 +135,35 @@ const kZKSKeyCodeMap = {
|
||||||
F10: "VK_F10",
|
F10: "VK_F10",
|
||||||
F11: "VK_F11",
|
F11: "VK_F11",
|
||||||
F12: "VK_F12",
|
F12: "VK_F12",
|
||||||
|
TAB: "VK_TAB",
|
||||||
|
ENTER: "VK_RETURN",
|
||||||
|
ESCAPE: "VK_ESCAPE",
|
||||||
|
SPACE: "VK_SPACE",
|
||||||
|
ARROWLEFT: "VK_LEFT",
|
||||||
|
ARROWRIGHT: "VK_RIGHT",
|
||||||
|
ARROWUP: "VK_UP",
|
||||||
|
ARROWDOWN: "VK_DOWN",
|
||||||
|
DELETE: "VK_DELETE",
|
||||||
|
BACKSPACE: "VK_BACK",
|
||||||
};
|
};
|
||||||
|
|
||||||
var gZenKeyboardShortcuts = {
|
var gZenKeyboardShortcuts = {
|
||||||
init() {
|
init() {
|
||||||
|
if (!Services.prefs.getBoolPref("zen.keyboard.shortcuts.enabled")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._initShortcuts();
|
this._initShortcuts();
|
||||||
},
|
},
|
||||||
|
|
||||||
get _savedShortcuts() {
|
get _savedShortcuts() {
|
||||||
if (!this.__savedShortcuts) {
|
if (!this.__savedShortcuts) {
|
||||||
try {
|
try {
|
||||||
this.__savedShortcuts = JSON.parse(Services.prefs.getStringPref(kZKSStorageKey));
|
const data = Services.prefs.getStringPref(kZKSStorageKey);
|
||||||
|
if (data.length == 0) {
|
||||||
|
this._startUpShortcuts();
|
||||||
|
return this._savedShortcuts;
|
||||||
|
}
|
||||||
|
this.__savedShortcuts = JSON.parse(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Zen CKS: Error parsing saved shortcuts", e);
|
console.error("Zen CKS: Error parsing saved shortcuts", e);
|
||||||
this.__savedShortcuts = {};
|
this.__savedShortcuts = {};
|
||||||
|
@ -126,13 +172,46 @@ var gZenKeyboardShortcuts = {
|
||||||
return this.__savedShortcuts;
|
return this.__savedShortcuts;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_startUpShortcuts() {
|
||||||
|
this.__savedShortcuts = {};
|
||||||
|
this._addDefaultShortcuts();
|
||||||
|
this._saveShortcuts();
|
||||||
|
},
|
||||||
|
|
||||||
|
_saveShortcuts() {
|
||||||
|
Services.prefs.setStringPref(kZKSStorageKey, JSON.stringify(this._savedShortcuts));
|
||||||
|
},
|
||||||
|
|
||||||
|
_parseDefaultShortcut(shortcut) {
|
||||||
|
let ctrl = shortcut.includes("Ctrl+");
|
||||||
|
let alt = shortcut.includes("Alt+");
|
||||||
|
let shift = shortcut.includes("Shift+");
|
||||||
|
let meta = shortcut.includes("Meta+");
|
||||||
|
let key = shortcut.replace(/Ctrl\+|Alt\+|Shift\+|Meta\+/g, "");
|
||||||
|
if (["Tab", "Enter", "Escape", "Space", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(key)) {
|
||||||
|
return { ctrl, alt, shift, meta, key: undefined, keycode: key };
|
||||||
|
}
|
||||||
|
let isKeyCode = key.length > 1;
|
||||||
|
return { ctrl, alt, shift, meta,
|
||||||
|
key: isKeyCode ? undefined : key,
|
||||||
|
keycode: isKeyCode ? key : undefined };
|
||||||
|
},
|
||||||
|
|
||||||
|
_addDefaultShortcuts() {
|
||||||
|
for (let action in kZenDefaultShortcuts) {
|
||||||
|
if (!this._savedShortcuts[action]) {
|
||||||
|
this._savedShortcuts[action] = this._parseDefaultShortcut(kZenDefaultShortcuts[action]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
setShortcut(id, shortcut) {
|
setShortcut(id, shortcut) {
|
||||||
if (!shortcut) {
|
if (!shortcut) {
|
||||||
delete this._savedShortcuts[id];
|
delete this._savedShortcuts[id];
|
||||||
} else if (this.isValidShortcut(shortcut)) {
|
} else if (this.isValidShortcut(shortcut)) {
|
||||||
this._savedShortcuts[id] = shortcut;
|
this._savedShortcuts[id] = shortcut;
|
||||||
}
|
}
|
||||||
Services.prefs.setStringPref(kZKSStorageKey, JSON.stringify(this._savedShortcuts));
|
this._saveShortcuts();
|
||||||
},
|
},
|
||||||
|
|
||||||
_initShortcuts() {
|
_initShortcuts() {
|
||||||
|
@ -279,7 +358,3 @@ var gZenKeyboardShortcuts = {
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
gZenKeyboardShortcuts.init();
|
|
||||||
|
|
||||||
// Section: gZenKeyboardShortcutsFunctions
|
|
||||||
|
|
|
@ -422,7 +422,6 @@ var gZenViewSplitter = new class {
|
||||||
// see browser-custom-elements.js's patch
|
// see browser-custom-elements.js's patch
|
||||||
tab.linkedBrowser.zenModeActive = active;
|
tab.linkedBrowser.zenModeActive = active;
|
||||||
try {
|
try {
|
||||||
console.info(tab.linkedBrowser);
|
|
||||||
tab.linkedBrowser.docShellIsActive = active;
|
tab.linkedBrowser.docShellIsActive = active;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -574,4 +573,26 @@ var gZenViewSplitter = new class {
|
||||||
targetWindow.gBrowser.selectedTab = tab;
|
targetWindow.gBrowser.selectedTab = tab;
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleShortcut(gridType) {
|
||||||
|
if (gridType === "unsplit" && this.currentView >= 0) {
|
||||||
|
this.unsplitCurrentView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.currentView >= 0) {
|
||||||
|
this._data[this.currentView].gridType = gridType;
|
||||||
|
this.updateSplitView(window.gBrowser.selectedTab);
|
||||||
|
}
|
||||||
|
const tabs = gBrowser.tabs;
|
||||||
|
if (tabs.length < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let nextTabIndex = tabs.indexOf(gBrowser.selectedTab) + 1;
|
||||||
|
if (nextTabIndex >= tabs.length) {
|
||||||
|
nextTabIndex = 0;
|
||||||
|
} else if (nextTabIndex < 0) {
|
||||||
|
nextTabIndex = tabs.length - 1;
|
||||||
|
}
|
||||||
|
this.splitTabs([gBrowser.selectedTab, tabs[nextTabIndex]]);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -421,7 +421,16 @@ var ZenWorkspaces = {
|
||||||
|
|
||||||
async contextDelete() {
|
async contextDelete() {
|
||||||
await this.removeWorkspace(this._contextMenuId);
|
await this.removeWorkspace(this._contextMenuId);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
async changeWorkspaceShortcut() {
|
||||||
|
// Cycle through workspaces
|
||||||
|
let workspaces = await this._workspaces();
|
||||||
|
let activeWorkspace = workspaces.workspaces.find(workspace => workspace.used);
|
||||||
|
let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace);
|
||||||
|
let nextWorkspace = workspaces.workspaces[workspaceIndex + 1] || workspaces.workspaces[0];
|
||||||
|
this.changeWorkspace(nextWorkspace);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ZenWorkspaces.init();
|
ZenWorkspaces.init();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue