mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:59:59 +02:00
feat: Unified pinned tab close shortcut behavior
This commit introduces a unified behavior for the pinned tab close shortcut, controlled by a single preference `zen.pinned-tab-manager.close-shortcut-behavior`. The previous implementation relied on multiple separate preferences: - `zen.pinned-tab-manager.reset-pinned-tab-on-close-shortcut` - `zen.pinned-tab-manager.unload-pinned-tab-on-close-shortcut` - `zen.pinned-tab-manager.change-pinned-tab-on-close-shortcut` - `zen.pinned-tab-manager.close-pinned-tab-on-close-shortcut` This new unified approach simplifies the configuration and offers more granular control over the desired behavior. The new preference `zen.pinned-tab-manager.close-shortcut-behavior` accepts the following values: - `close`: Closes the selected pinned tab. - `reset`: Resets the selected pinned tab to its stored state. - `unload`: Unloads the selected pinned tab. - `switch`: Switches to the next unpinned tab. - `reset-unload-switch`: Resets, unloads, and switches the selected pinned tab. - `unload-switch`: Unloads and switches the selected pinned tab. - `reset-switch`: Resets and switches the selected pinned tab. This unified approach provides greater flexibility and simplifies the user experience.
This commit is contained in:
parent
e28f8e131e
commit
4217882981
1 changed files with 42 additions and 41 deletions
|
@ -2,10 +2,7 @@
|
|||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabRestorePinnedTabsToPinnedUrl', 'zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabResetOnCloseShortcut', 'zen.pinned-tab-manager.reset-pinned-tab-on-close-shortcut', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabUnloadOnCloseShortcut', 'zen.pinned-tab-manager.unload-pinned-tab-on-close-shortcut', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabChangeOnCloseShortcut', 'zen.pinned-tab-manager.change-pinned-tab-on-close-shortcut', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabCloseOnCloseShortcut', 'zen.pinned-tab-manager.close-pinned-tab-on-close-shortcut', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch');
|
||||
|
||||
class ZenPinnedTabsObserver {
|
||||
static ALL_EVENTS = ['TabPinned', 'TabUnpinned'];
|
||||
|
@ -126,51 +123,55 @@
|
|||
|
||||
_onCloseTabShortcut(event) {
|
||||
if (
|
||||
event &&
|
||||
(event.ctrlKey || event.metaKey || event.altKey) &&
|
||||
gBrowser.selectedTab?.pinned
|
||||
!event ||
|
||||
!(event.ctrlKey || event.metaKey || event.altKey) ||
|
||||
!gBrowser.selectedTab?.pinned
|
||||
) {
|
||||
const selectedTab = gBrowser.selectedTab;
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedTab) {
|
||||
const selectedTab = gBrowser.selectedTab;
|
||||
if (!selectedTab) return;
|
||||
|
||||
if (lazy.zenPinnedTabCloseOnCloseShortcut) {
|
||||
gBrowser.removeTab(selectedTab, { animate: true });
|
||||
const behavior = lazy.zenPinnedTabCloseShortcutBehavior;
|
||||
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if(lazy.zenPinnedTabChangeOnCloseShortcut) {
|
||||
|
||||
let nextTab = gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||
direction: 1,
|
||||
filter: tab => !tab.hidden && !tab.pinned,
|
||||
});
|
||||
|
||||
if (!nextTab) {
|
||||
nextTab = gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||
direction: -1,
|
||||
filter: tab => !tab.hidden && !tab.pinned,
|
||||
});
|
||||
}
|
||||
|
||||
gBrowser.selectedTab = nextTab;
|
||||
}
|
||||
|
||||
|
||||
if (lazy.zenPinnedTabResetOnCloseShortcut) {
|
||||
switch (behavior) {
|
||||
case 'close':
|
||||
gBrowser.removeTab(selectedTab, { animate: true });
|
||||
break;
|
||||
case 'reset-unload-switch':
|
||||
case 'unload-switch':
|
||||
case 'reset-switch':
|
||||
case 'switch':
|
||||
this._handleTabSwitch(selectedTab);
|
||||
if (behavior.includes('reset')) {
|
||||
this._resetTabToStoredState(selectedTab);
|
||||
}
|
||||
|
||||
|
||||
if(lazy.zenPinnedTabUnloadOnCloseShortcut) {
|
||||
if (behavior.includes('unload')) {
|
||||
gBrowser.discardBrowser(selectedTab);
|
||||
}
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
case 'reset':
|
||||
this._resetTabToStoredState(selectedTab);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
_handleTabSwitch(selectedTab) {
|
||||
const findNextTab = (direction) =>
|
||||
gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||
direction,
|
||||
filter: tab => !tab.hidden && !tab.pinned,
|
||||
});
|
||||
|
||||
const nextTab = findNextTab(1) || findNextTab(-1);
|
||||
if (nextTab) {
|
||||
gBrowser.selectedTab = nextTab;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue