Skip to content

Commit

Permalink
deduplicate in additional windows
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdc committed Dec 11, 2024
1 parent ca9f852 commit a97874d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/services/DeduplicateTab.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { App, FileView, TFile, WorkspaceLeaf } from "obsidian";
import { loadDeferredLeaf } from "./LoadDeferredLeaf";

function iterateRootOrFloatingLeaves(
app: App,
callback: (leaf: WorkspaceLeaf) => void
) {
const workspace = app.workspace;
const { rootSplit, floatingSplit } = workspace;
workspace.iterateLeaves(rootSplit, callback);
workspace.iterateLeaves(floatingSplit, callback);
}

export function deduplicateTab(
app: App,
file: TFile | null,
focus = true
): WorkspaceLeaf | null {
if (!file) return null;
const targetLeaves: WorkspaceLeaf[] = [];
app.workspace.iterateRootLeaves((leaf) => {
iterateRootOrFloatingLeaves(app, (leaf) => {
if (leaf.view instanceof FileView && leaf.view.file === file) {
targetLeaves.push(leaf);
} else if (leaf.getViewState().state?.file === file.path) {
Expand Down

0 comments on commit a97874d

Please sign in to comment.