diff --git a/src/components/NavigationContainer.tsx b/src/components/NavigationContainer.tsx index d1b4a8a..e44ae59 100644 --- a/src/components/NavigationContainer.tsx +++ b/src/components/NavigationContainer.tsx @@ -21,6 +21,7 @@ import { autoCloseOldEphemeralTabs, initEphemeralTabs, installTabHeaderHandlers, + makeDblclickedFileNonEphemeral, makeLeafEphemeralOnEditorChange, makeLeafNonEphemeral, makeTabNonEphemeralAutomatically, @@ -178,6 +179,9 @@ export const NavigationContainer = () => { ref.current.toggleClass("tab-index-view-cue", false); } }); + plugin.registerDomEvent(document, "dblclick", (event) => { + makeDblclickedFileNonEphemeral(app, event); + }); plugin.addCommand({ id: "toggle-zen-mode", name: "Toggle zen mode", diff --git a/src/services/EphemeralTabs.ts b/src/services/EphemeralTabs.ts index 0b91c28..20633ab 100644 --- a/src/services/EphemeralTabs.ts +++ b/src/services/EphemeralTabs.ts @@ -5,7 +5,11 @@ import { WorkspaceLeaf, WorkspaceParent, } from "obsidian"; -import { iterateRootOrFloatingLeaves, iterateSidebarLeaves } from "./GetTabs"; +import { + getOpenFileOfLeaf, + iterateRootOrFloatingLeaves, + iterateSidebarLeaves, +} from "./GetTabs"; import { useViewState } from "src/models/ViewState"; import { useSettings } from "src/models/PluginContext"; import { Identifier } from "src/models/VTWorkspace"; @@ -167,3 +171,26 @@ export function autoCloseOldEphemeralTabs(app: App) { iterateRootOrFloatingLeaves(app, (leaf) => groups.add(leaf.parent)); groups.forEach((group) => autoCloseOldEphemeralTabsForGroup(group)); } + +export function makeDblclickedFileNonEphemeral(app: App, event: MouseEvent) { + const target = event.target as HTMLElement; + const fileTitleEl = target.matchParent(".nav-file-title"); + if (!fileTitleEl) return; + const path = fileTitleEl.getAttribute("data-path"); + if (!path) return; + const file = app.vault.getAbstractFileByPath(path); + if (!file) return; + let activeTime = 0; + let targetLeaf: WorkspaceLeaf | null = null; + app.workspace.iterateAllLeaves((leaf) => { + const leafFile = getOpenFileOfLeaf(app, leaf); + if (!leafFile || leafFile.path !== file.path) return; + if (leaf.activeTime >= activeTime) { + activeTime = leaf.activeTime; + targetLeaf = leaf; + } + }); + if (targetLeaf) { + makeLeafNonEphemeral(targetLeaf); + } +}