mirror of
https://github.com/zen-browser/components.git
synced 2025-07-10 06:35:30 +02:00
Fix: Add middle click to handle close pinned tab and handle tab switch
This commit fixes an issue where middle clicking a pinned tab would not follow the behavior of pinned tab close shortcut.
This commit is contained in:
parent
9a1beadc03
commit
d51cb4f1e3
1 changed files with 21 additions and 9 deletions
|
@ -9,7 +9,7 @@
|
||||||
constructor() {
|
constructor() {
|
||||||
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, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch');
|
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch');
|
||||||
|
|
||||||
this.#listenPinnedTabEvents();
|
this.#listenPinnedTabEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +49,15 @@
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "TabPinned":
|
case "TabPinned":
|
||||||
this._setPinnedAttributes(tab);
|
this._setPinnedAttributes(tab);
|
||||||
|
tab._zenClickEventListener = this._onTabClick.bind(this, tab);
|
||||||
|
tab.addEventListener("click", tab._zenClickEventListener);
|
||||||
break;
|
break;
|
||||||
case "TabUnpinned":
|
case "TabUnpinned":
|
||||||
this._removePinnedAttributes(tab);
|
this._removePinnedAttributes(tab);
|
||||||
|
if (tab._zenClickEventListener) {
|
||||||
|
tab.removeEventListener("click", tab._zenClickEventListener);
|
||||||
|
delete tab._zenClickEventListener;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn('ZenPinnedTabManager: Unhandled tab event', action);
|
console.warn('ZenPinnedTabManager: Unhandled tab event', action);
|
||||||
|
@ -59,6 +65,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onTabClick(tab, e) {
|
||||||
|
if (e.button === 1) {
|
||||||
|
this._onCloseTabShortcut(e, tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resetPinnedTab(tab) {
|
resetPinnedTab(tab) {
|
||||||
|
|
||||||
if (!tab) {
|
if (!tab) {
|
||||||
|
@ -113,17 +125,15 @@
|
||||||
!!tabData.zenPinnedIcon ? tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon) : tab.removeAttribute("zen-pinned-icon");
|
!!tabData.zenPinnedIcon ? tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon) : tab.removeAttribute("zen-pinned-icon");
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCloseTabShortcut(event) {
|
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) {
|
||||||
if (
|
if (
|
||||||
!event ||
|
!selectedTab?.pinned
|
||||||
!(event.ctrlKey || event.metaKey || event.altKey) ||
|
|
||||||
!gBrowser.selectedTab?.pinned
|
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedTab = gBrowser.selectedTab;
|
event.stopPropagation();
|
||||||
if (!selectedTab) return;
|
event.preventDefault();
|
||||||
|
|
||||||
const behavior = lazy.zenPinnedTabCloseShortcutBehavior;
|
const behavior = lazy.zenPinnedTabCloseShortcutBehavior;
|
||||||
|
|
||||||
|
@ -150,11 +160,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleTabSwitch(selectedTab) {
|
_handleTabSwitch(selectedTab) {
|
||||||
|
if(selectedTab !== gBrowser.selectedTab) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const findNextTab = (direction) =>
|
const findNextTab = (direction) =>
|
||||||
gBrowser.tabContainer.findNextTab(selectedTab, {
|
gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||||
direction,
|
direction,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue