diff --git a/src/services/bookmarks.actions.ts b/src/services/bookmarks.actions.ts index 46a8f74c..1303322d 100644 --- a/src/services/bookmarks.actions.ts +++ b/src/services/bookmarks.actions.ts @@ -1510,3 +1510,21 @@ export async function prepareBookmarks() { if (!Bookmarks.reactive.tree.length) await Bookmarks.load() return true } + +const flashAnimationTimeouts = new Map() + +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) + ) +} diff --git a/src/services/keybindings.actions.ts b/src/services/keybindings.actions.ts index 79eb82a2..840a714a 100644 --- a/src/services/keybindings.actions.ts +++ b/src/services/keybindings.actions.ts @@ -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)) } }