mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 14:19:57 +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 = {};
|
const lazy = {};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabRestorePinnedTabsToPinnedUrl', 'zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url', false);
|
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, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch');
|
||||||
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);
|
|
||||||
|
|
||||||
class ZenPinnedTabsObserver {
|
class ZenPinnedTabsObserver {
|
||||||
static ALL_EVENTS = ['TabPinned', 'TabUnpinned'];
|
static ALL_EVENTS = ['TabPinned', 'TabUnpinned'];
|
||||||
|
@ -126,51 +123,55 @@
|
||||||
|
|
||||||
_onCloseTabShortcut(event) {
|
_onCloseTabShortcut(event) {
|
||||||
if (
|
if (
|
||||||
event &&
|
!event ||
|
||||||
(event.ctrlKey || event.metaKey || event.altKey) &&
|
!(event.ctrlKey || event.metaKey || event.altKey) ||
|
||||||
gBrowser.selectedTab?.pinned
|
!gBrowser.selectedTab?.pinned
|
||||||
) {
|
) {
|
||||||
const selectedTab = gBrowser.selectedTab;
|
|
||||||
|
|
||||||
if (selectedTab) {
|
|
||||||
|
|
||||||
if (lazy.zenPinnedTabCloseOnCloseShortcut) {
|
|
||||||
gBrowser.removeTab(selectedTab, { animate: true });
|
|
||||||
|
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lazy.zenPinnedTabChangeOnCloseShortcut) {
|
const selectedTab = gBrowser.selectedTab;
|
||||||
|
if (!selectedTab) return;
|
||||||
|
|
||||||
let nextTab = gBrowser.tabContainer.findNextTab(selectedTab, {
|
const behavior = lazy.zenPinnedTabCloseShortcutBehavior;
|
||||||
direction: 1,
|
|
||||||
filter: tab => !tab.hidden && !tab.pinned,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!nextTab) {
|
switch (behavior) {
|
||||||
nextTab = gBrowser.tabContainer.findNextTab(selectedTab, {
|
case 'close':
|
||||||
direction: -1,
|
gBrowser.removeTab(selectedTab, { animate: true });
|
||||||
filter: tab => !tab.hidden && !tab.pinned,
|
break;
|
||||||
});
|
case 'reset-unload-switch':
|
||||||
}
|
case 'unload-switch':
|
||||||
|
case 'reset-switch':
|
||||||
gBrowser.selectedTab = nextTab;
|
case 'switch':
|
||||||
}
|
this._handleTabSwitch(selectedTab);
|
||||||
|
if (behavior.includes('reset')) {
|
||||||
|
|
||||||
if (lazy.zenPinnedTabResetOnCloseShortcut) {
|
|
||||||
this._resetTabToStoredState(selectedTab);
|
this._resetTabToStoredState(selectedTab);
|
||||||
}
|
}
|
||||||
|
if (behavior.includes('unload')) {
|
||||||
|
|
||||||
if(lazy.zenPinnedTabUnloadOnCloseShortcut) {
|
|
||||||
gBrowser.discardBrowser(selectedTab);
|
gBrowser.discardBrowser(selectedTab);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 'reset':
|
||||||
|
this._resetTabToStoredState(selectedTab);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
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