Skip to content

Commit

Permalink
fix: kb: open all selected bookmarks
Browse files Browse the repository at this point in the history
(resolves #1980)
  • Loading branch information
mbnuqw committed Jan 26, 2025
1 parent 88ad639 commit 62d9758
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
18 changes: 18 additions & 0 deletions src/services/bookmarks.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,3 +1510,21 @@ export async function prepareBookmarks() {
if (!Bookmarks.reactive.tree.length) await Bookmarks.load()
return true
}

const flashAnimationTimeouts = new Map<ID, number>()

export function triggerFlashAnimation(panelId: ID, bookmarkId: ID) {
const elId = 'bookmark' + panelId + bookmarkId
const el = document.getElementById(elId)
if (!el) return

el.classList.add('-middle-click')
clearTimeout(flashAnimationTimeouts.get(bookmarkId))
flashAnimationTimeouts.set(
bookmarkId,
setTimeout(() => {
el?.classList.remove('-middle-click')
flashAnimationTimeouts.delete(bookmarkId)
}, 300)
)
}
71 changes: 41 additions & 30 deletions src/services/keybindings.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,43 +464,54 @@ function onKeyActivate(): void {

// Bookmarks
else if (Selection.isBookmarks()) {
const targetId = Selection.getFirst()
const target = Bookmarks.reactive.byId[targetId]
if (!target) return

const actPanel = Sidebar.panelsById[Sidebar.activePanelId]
if (!actPanel) return
const ids = Selection.get()
if (ids.length === 1) {
const target = Bookmarks.reactive.byId[ids[0]]
if (!target) return

if (target.type === 'folder') {
const isExpanded = Bookmarks.reactive.expanded[Sidebar.activePanelId]?.[target.id]
if (isExpanded) Bookmarks.foldBookmark(target.id, Sidebar.activePanelId)
else Bookmarks.expandBookmark(target.id, Sidebar.activePanelId)
}
if (target.type === 'folder') {
const isExpanded = Bookmarks.reactive.expanded[Sidebar.activePanelId]?.[target.id]
if (isExpanded) Bookmarks.foldBookmark(target.id, Sidebar.activePanelId)
else Bookmarks.expandBookmark(target.id, Sidebar.activePanelId)
return
}

if (target.type === 'bookmark') {
if (Settings.state.activateOpenBookmarkTab && target.isOpen) {
const tab = Tabs.list.find(t => t.url === target.url)
if (tab) {
browser.tabs.update(tab.id, { active: true })
return
if (target.type === 'bookmark') {
const actPanel = Sidebar.panelsById[Sidebar.activePanelId]
if (!actPanel) return

if (Settings.state.activateOpenBookmarkTab && target.isOpen) {
const tab = Tabs.list.find(t => t.url === target.url)
if (tab) {
browser.tabs.update(tab.id, { active: true })
return
}
}
}

// Check if new tab is needed
let newTabNeededInActPanel = false
if (Utils.isTabsPanel(actPanel) && !newTabNeededInActPanel) {
const actTab = Tabs.byId[Tabs.activeId]
if (actTab) {
const inPanel = Settings.state.pinnedTabsPosition === 'panel'
newTabNeededInActPanel = actTab.panelId !== actPanel.id || (actTab.pinned && !inPanel)
// Check if new tab is needed
let newTabNeededInActPanel = false
if (Utils.isTabsPanel(actPanel) && !newTabNeededInActPanel) {
const actTab = Tabs.byId[Tabs.activeId]
if (actTab) {
const inPanel = Settings.state.pinnedTabsPosition === 'panel'
newTabNeededInActPanel = actTab.panelId !== actPanel.id || (actTab.pinned && !inPanel)
}
}
}

const conf = Bookmarks.getMouseOpeningConf(0)
const useActiveTab = !newTabNeededInActPanel && conf.useActiveTab
const activateFirstTab = newTabNeededInActPanel || conf.activateFirstTab
Bookmarks.open([targetId], conf.dst, useActiveTab, activateFirstTab)
const conf = Bookmarks.getMouseOpeningConf(0)
const useActiveTab = !newTabNeededInActPanel && conf.useActiveTab
const activateFirstTab = newTabNeededInActPanel || conf.activateFirstTab
Bookmarks.open(ids, conf.dst, useActiveTab, activateFirstTab)
}
} else {
const panelId = Sidebar.getRecentTabsPanelId()
const panel = Sidebar.panelsById[panelId]
if (!Utils.isTabsPanel(panel)) return
const dst = { panelId, index: Tabs.getIndexForNewTab(panel) }
Bookmarks.open(ids, dst, false, false)
}

ids.forEach(id => Bookmarks.triggerFlashAnimation(Sidebar.activePanelId, id))
}
}

Expand Down

0 comments on commit 62d9758

Please sign in to comment.