Skip to content

Commit

Permalink
chore: followup bug 1939535 - TOM indicates collapsed groups and hide…
Browse files Browse the repository at this point in the history
…s their tabs
  • Loading branch information
onemen committed Jan 16, 2025
1 parent 3fdf31f commit b3dffec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
44 changes: 37 additions & 7 deletions addon/chrome/content/click/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,29 +989,59 @@ Tabmix.allTabs = {
return row;
};

// we modify here _populate from TabsListBase class
Object.getPrototypeOf(TabsPanel.prototype)._populate = function() {
// TabsListBase class
// modify _populateDOM and _populate add _tabmix_sortTabs

/** @type {MockedGeckoTypes.TabsListBase} */
const TabsListBase = Object.getPrototypeOf(TabsPanel.prototype);

if (Tabmix.isVersion(1350)) {
TabsListBase._tabmix_sortTabs = function() {
return this.gBrowser.tabs.slice()
.sort((a, b) => {
if (a.group?.id === b.group?.id) {
return a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1;
}
const labelA = a.group ? a.group.label.toLowerCase() : a.label.toLowerCase();
const labelB = b.group ? b.group.label.toLowerCase() : b.label.toLowerCase();
return labelA > labelB ? 1 : -1;
});
};
} else {
TabsListBase._tabmix_sortTabs = function() {
return this.gBrowser.tabs.slice()
.sort((a, b) => (a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1));
};
}

TabsListBase._populateDOM = function() {
let fragment = this.doc.createDocumentFragment();
let currentGroupId;

const sortTabs = () => [...this.gBrowser.tabs]
.sort((a, b) => (a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1));
const tabs = typeof sortTabsButton === "object" && sortTabsButton.checked ?
sortTabs() : this.gBrowser.tabs;
this._tabmix_sortTabs() : this.gBrowser.tabs;

for (let tab of tabs) {
if (this.filterFn(tab)) {
if (Tabmix.isVersion(1350) && tab.group && tab.group.id != currentGroupId) {
fragment.appendChild(this._createGroupRow(tab.group));
currentGroupId = tab.group.id;
}
fragment.appendChild(this._createRow(tab));
if (!tab.group?.collapsed) {
fragment.appendChild(this._createRow(tab));
}
}
}

this._addElement(fragment);
this._setupListeners();
};

if (!Tabmix.isVersion(1360)) {
TabsListBase._populate = function() {
this._populateDOM();
this._setupListeners();
};
}
}
},

Expand Down
7 changes: 6 additions & 1 deletion types/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ declare namespace MockedGeckoTypes {
gBrowser: TabBrowser;
}

type MozTabbrowserTabGroup = {color: string; id: string; label: string};
type MozTabbrowserTabGroup = {color: string; collapsed: boolean; id: string; label: string};

interface TabsPanel extends TabsListBase {
prototype: TabsListBase;
Expand Down Expand Up @@ -515,15 +515,20 @@ declare namespace MockedGeckoTypes {
handleEvent(event: Event): void;
_selectTab(tab: BrowserTab): void;
_populate(): void;
_populateDOM(): void;
_addElement(elementOrFragment: DocumentFragment | HTMLElement): void;
_cleanup(): void;
_createRow(tab: BrowserTab): TabsPanelRow;
_createGroupRow(group: MozTabbrowserTabGroup): TabsPanelRow;
_setupListeners(): void;
_cleanupListeners(): void;
_tabAttrModified(tab: BrowserTab): void;
_moveTab(tab: BrowserTab): void;
_addTab(newtab: BrowserTab): void;
_tabClose(tab: BrowserTab): void;
_removeItem(item: TabsPanelRow, tab: BrowserTab): void;

_tabmix_sortTabs(): BrowserTab[];
}

interface gTabsPanel {
Expand Down

0 comments on commit b3dffec

Please sign in to comment.