-
-
Couldn't load subscription status.
- Fork 1.1k
feat: improve tab navigation and cycling #9441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 16 commits
4903575
b1253bf
c6769bf
42fd45d
f0c69b7
2e7ef05
b030f01
ae63f9d
1ebd642
f582029
4550322
9bc7609
f6f6b56
cf89eba
4462483
8237ee6
9d4d9e3
3183624
0b0ef8f
f1bb8f8
47e3779
6f608db
ed3f1ff
da26a8a
ed9ecc4
a75400a
5756c86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,15 @@ diff --git a/toolkit/content/widgets/tabbox.js b/toolkit/content/widgets/tabbox. | |
| index 70afbfc87d543971e6f8a0661a44b682920a7bc4..2f767296db8043318fab2aeb39bfc5eee090b258 100644 | ||
| --- a/toolkit/content/widgets/tabbox.js | ||
| +++ b/toolkit/content/widgets/tabbox.js | ||
| @@ -213,7 +213,7 @@ | ||
| @@ -125,6 +125,7 @@ | ||
|
|
||
| const { ShortcutUtils } = imports; | ||
|
|
||
| + return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about it, instead of adding a return here (which would invalidate the use of cmd+opt+arrows), instead I would remove just this line: https://searchfox.org/firefox-main/source/toolkit/modules/ShortcutUtils.sys.mjs#349 |
||
| switch (ShortcutUtils.getSystemActionForEvent(event)) { | ||
| case ShortcutUtils.CYCLE_TABS: | ||
| Glean.browserUiInteraction.keyboard["ctrl-tab"].add(1); | ||
| @@ -213,7 +214,7 @@ | ||
| ) { | ||
| this._inAsyncOperation = false; | ||
| if (oldPanel != this._selectedPanel) { | ||
|
|
@@ -11,7 +19,7 @@ index 70afbfc87d543971e6f8a0661a44b682920a7bc4..2f767296db8043318fab2aeb39bfc5ee | |
| this._selectedPanel?.classList.add("deck-selected"); | ||
| } | ||
| this.setAttribute("selectedIndex", val); | ||
| @@ -610,7 +610,7 @@ | ||
| @@ -610,7 +611,7 @@ | ||
| if (!tab) { | ||
| return; | ||
| } | ||
|
|
@@ -20,7 +28,7 @@ index 70afbfc87d543971e6f8a0661a44b682920a7bc4..2f767296db8043318fab2aeb39bfc5ee | |
| if (otherTab != tab && otherTab.selected) { | ||
| otherTab._selected = false; | ||
| } | ||
| @@ -823,7 +823,7 @@ | ||
| @@ -823,7 +824,7 @@ | ||
| if (tab == startTab) { | ||
| return null; | ||
| } | ||
|
|
@@ -29,12 +37,42 @@ index 70afbfc87d543971e6f8a0661a44b682920a7bc4..2f767296db8043318fab2aeb39bfc5ee | |
| return tab; | ||
| } | ||
| } | ||
| @@ -888,7 +888,7 @@ | ||
| @@ -885,10 +886,18 @@ | ||
| * @param {boolean} [aWrap] | ||
| */ | ||
| advanceSelectedTab(aDir, aWrap) { | ||
| + | ||
| + const basePref = Services.prefs.getStringPref('zen.tabs.unloaded-navigation-mode', 'never'); | ||
| + const invertedState = Services.prefs.getBoolPref('zen.tabs.unloaded-navigation-mode.inverted', false); | ||
| + const includeUnloaded = (basePref === 'always' && !invertedState) || (basePref === 'never' && invertedState); | ||
| + const tabFilter = includeUnloaded | ||
| + ? (tab => tab.visible) | ||
| + : (tab => tab.visible && !tab.hasAttribute('pending')); | ||
mr-cheffy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| + | ||
| let { ariaFocusedItem } = this; | ||
| let startTab = ariaFocusedItem; | ||
| if (!ariaFocusedItem || !this.allTabs.includes(ariaFocusedItem)) { | ||
| - startTab = this.selectedItem; | ||
| + startTab = gZenGlanceManager.getFocusedTab(aDir) || this.selectedItem; | ||
| } | ||
| let newTab = null; | ||
|
|
||
|
|
||
| @@ -896,15 +905,15 @@ | ||
| // which has a random placement in this.allTabs. | ||
| if (startTab.hidden) { | ||
| if (aDir == 1) { | ||
| - newTab = this.allTabs.find(tab => tab.visible); | ||
nikvnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| + newTab = this.allTabs.find(tabFilter); | ||
| } else { | ||
| - newTab = this.allTabs.findLast(tab => tab.visible); | ||
| + newTab = this.allTabs.findLast(tabFilter); | ||
| } | ||
| } else { | ||
| newTab = this.findNextTab(startTab, { | ||
| direction: aDir, | ||
| wrap: aWrap, | ||
| - filter: tab => tab.visible, | ||
| + filter: tabFilter, | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1051,8 +1051,43 @@ class nsZenKeyboardShortcutsVersioner { | |
| } | ||
| } | ||
| if (version < 10) { | ||
| // Migrate from version 9 to 10 | ||
| // 1) Add the new pin/unpin tab toggle shortcut with Ctrl+Shift+D | ||
| // 1) Migrate from version 9 to 10 | ||
| // In this new version, we add customizable shortcuts for switching to the next/previous tab and toggling unloaded tab cycling. | ||
| data.push( | ||
| new KeyShortcut( | ||
| 'zen-tab-next-shortcut', | ||
| 'TAB', | ||
| 'VK_TAB', | ||
| 'windowAndTabManagement', | ||
| nsKeyShortcutModifiers.fromObject({ accel: true }), | ||
| 'cmd_zenTabNext', | ||
| 'zen-tab-next-shortcut' | ||
| ) | ||
| ); | ||
| data.push( | ||
| new KeyShortcut( | ||
| 'zen-tab-prev-shortcut', | ||
| 'TAB', | ||
| 'VK_TAB', | ||
| 'windowAndTabManagement', | ||
| nsKeyShortcutModifiers.fromObject({ accel: true, shift: true }), | ||
| 'cmd_zenTabPrev', | ||
| 'zen-tab-prev-shortcut' | ||
| ) | ||
| ); | ||
| data.push( | ||
| new KeyShortcut( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a shortcut I would just have it as a global preference it can be toggled, removing |
||
| 'zen-toggle-unloaded-cycling-shortcut', | ||
| '', | ||
| '', | ||
| 'windowAndTabManagement', | ||
| nsKeyShortcutModifiers.fromObject({}), | ||
| 'cmd_zenToggleUnloadedCycling', | ||
| 'zen-toggle-unloaded-cycling-shortcut' | ||
| ) | ||
| ); | ||
|
|
||
| // 2) Add the new pin/unpin tab toggle shortcut with Ctrl+Shift+D | ||
| data.push( | ||
| new KeyShortcut( | ||
| 'zen-toggle-pin-tab', | ||
|
|
@@ -1065,7 +1100,7 @@ class nsZenKeyboardShortcutsVersioner { | |
| ) | ||
| ); | ||
|
|
||
| // 2) Add shortcut to expand Glance into a full tab: Default Accel+O | ||
| // 3) Add shortcut to expand Glance into a full tab: Default Accel+O | ||
| data.push( | ||
| new KeyShortcut( | ||
| 'zen-glance-expand', | ||
|
|
@@ -1108,10 +1143,8 @@ var gZenKeyboardShortcutsManager = { | |
| async init() { | ||
| if (this.inBrowserView) { | ||
| const loadedShortcuts = await this._loadSaved(); | ||
|
|
||
| this._currentShortcutList = this.versioner.fixedKeyboardShortcuts(loadedShortcuts); | ||
| this._currentShortcutList = this.versioner.fixedKeyboardShortcuts(loadedShortcuts) || []; | ||
| this._applyShortcuts(); | ||
|
|
||
| await this._saveShortcuts(); | ||
| } | ||
| }, | ||
|
|
@@ -1216,6 +1249,47 @@ var gZenKeyboardShortcutsManager = { | |
| this.triggerShortcutRebuild(); | ||
| }, | ||
|
|
||
| _registerPrecedentShortcut(shortcut, browser) { | ||
nikvnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const listener = (event) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new event is being made on every key added, I would add a single event handler and check on a list of known precedent shortcuts |
||
| let keyMatch = false; | ||
| if (shortcut.getKeyName()) { | ||
| keyMatch = event.key.toLowerCase() === shortcut.getKeyName().toLowerCase(); | ||
| } else if (shortcut.getKeyCode()) { | ||
| for (const [mapKey, mapValue] of Object.entries(KEYCODE_MAP)) { | ||
| if (mapValue === shortcut.getKeyCode()) { | ||
| if (mapKey.toLowerCase() === event.code.toLowerCase()) { | ||
| keyMatch = true; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!keyMatch) { | ||
| return; | ||
| } | ||
|
|
||
| const modifiers = shortcut.getModifiers(); | ||
| const accelPressed = AppConstants.platform === 'macosx' ? event.metaKey : event.ctrlKey; | ||
| const modifiersMatch = | ||
| modifiers.accel === accelPressed && | ||
| modifiers.alt === event.altKey && | ||
| modifiers.shift === event.shiftKey; | ||
|
|
||
| if (modifiersMatch) { | ||
| event.preventDefault(); | ||
| event.stopImmediatePropagation(); | ||
| const command = browser.document.getElementById(shortcut.getAction()); | ||
| if (command) { | ||
| command.doCommand(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| browser.addEventListener('keydown', listener, true); | ||
| browser.gZenKeyboardShortcutsManager._precedentListeners.push(listener); | ||
nikvnt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| _applyShortcuts() { | ||
| for (const browser of nsZenMultiWindowFeature.browsers) { | ||
| let mainKeyset = browser.document.getElementById(ZEN_MAIN_KEYSET_ID); | ||
|
|
@@ -1232,12 +1306,19 @@ var gZenKeyboardShortcutsManager = { | |
| // throw new Error('Child list not empty'); | ||
| //} | ||
|
|
||
| browser.gZenKeyboardShortcutsManager._precedentListeners = []; | ||
|
|
||
| for (let key of this._currentShortcutList) { | ||
| if (key.isInternal()) { | ||
| continue; | ||
| } | ||
| let child = key.toXHTMLElement(browser); | ||
| keyset.appendChild(child); | ||
|
|
||
| if (key.getID() === 'zen-tab-next-shortcut' || key.getID() === 'zen-tab-prev-shortcut') { | ||
nikvnt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this._registerPrecedentShortcut(key, browser); | ||
| } else { | ||
| let child = key.toXHTMLElement(browser); | ||
| keyset.appendChild(child); | ||
| } | ||
| } | ||
|
|
||
| this._applyDevtoolsShortcuts(browser); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.