Skip to content

Commit

Permalink
Fix order of recent tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
taupiqueur committed Jul 17, 2024
1 parent e192f9e commit 27390a5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/suggestion_providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ const newOpenTabSuggestion = tab => ({
export async function getOpenTabSuggestions(cx) {
const tabs = await chrome.tabs.query({})

const tabIds = cx.recentTabsManager.getRecentTabs()
const recentTabs = cx.recentTabsManager.getRecentTabs()

const tabIndexMap = new Map(
tabIds.map((tabId, index) => [
tabId, index
])
)
const tabMap = new Map

const sortedTabs = tabs.toSorted((tab, otherTab) =>
(tabIndexMap.get(tab.id) ?? -1) - (tabIndexMap.get(otherTab.id) ?? -1)
)
for (const tabId of recentTabs) {
tabMap.set(tabId, null)
}

// This is a cheap means to exclude the current tab.
if (sortedTabs[0].id === cx.tab.id) {
sortedTabs.shift()
for (const tab of tabs) {
tabMap.set(tab.id, tab)
}

return sortedTabs.map(newOpenTabSuggestion)
tabMap.delete(cx.tab.id)

return Array.from(
tabMap.values(),
newOpenTabSuggestion
)
}

// Closed tab suggestions ------------------------------------------------------
Expand Down

0 comments on commit 27390a5

Please sign in to comment.