Skip to content

Commit

Permalink
close: #99
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdc committed Jan 16, 2025
1 parent a4d4d02 commit 1a8938f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/NavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
autoCloseOldEphemeralTabs,
initEphemeralTabs,
installTabHeaderHandlers,
makeDblclickedFileNonEphemeral,
makeLeafEphemeralOnEditorChange,
makeLeafNonEphemeral,
makeTabNonEphemeralAutomatically,
Expand Down Expand Up @@ -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",
Expand Down
29 changes: 28 additions & 1 deletion src/services/EphemeralTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1a8938f

Please sign in to comment.