Skip to content

Commit d1c41a7

Browse files
undo leaf for context-menu
1 parent 9a24d36 commit d1c41a7

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/navtree/naveTree.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TFile, TFolder, Plugin, Menu, WorkspaceLeaf, MarkdownView } from 'obsidian';
1+
import { TFile, TFolder, Plugin, Menu } from 'obsidian';
22
import { ExplorerLeaf, ElementsObj, Pairs } from '../types/obsidian';
33

44
export function newNavTreeStart(plugin: Plugin) {
@@ -46,17 +46,13 @@ export function oldNavTreeChange(plugin: Plugin, pairs: Pairs) {
4646
if (file instanceof TFile) {
4747
// Create a new Menu object
4848
const menu = new Menu();
49-
const leaf = getLeafForFile(plugin, file)
50-
// Trigger the 'file-menu' event
51-
if (leaf) {
5249

53-
//@ts-ignore
54-
plugin.app.workspace.trigger("file-menu", menu, file, "file-explorer", leaf);
50+
// Trigger the 'file-menu' event
51+
//@ts-ignore
52+
plugin.app.workspace.trigger("file-menu", menu, file, "file-explorer");
5553

56-
// Show the menu at the mouse position
57-
menu.showAtMouseEvent(e);
58-
return
59-
}
54+
// Show the menu at the mouse position
55+
menu.showAtMouseEvent(e);
6056
}
6157
});
6258
targetInnerEl.style.display = "none"
@@ -123,18 +119,4 @@ export function getElementsObj(plugin: Plugin): ElementsObj | undefined {
123119
});
124120

125121
return elementsObj.folders.length > 0 ? elementsObj : undefined;
126-
}
127-
128-
function getLeafForFile(plugin: Plugin, file: TFile): WorkspaceLeaf | null {
129-
const leaves = plugin.app.workspace.getLeavesOfType("markdown");
130-
131-
for (const leaf of leaves) {
132-
const view = leaf.view;
133-
134-
if (view instanceof MarkdownView && view.file?.path === file.path) {
135-
return leaf; // Found the leaf for this file
136-
}
137-
}
138-
139-
return null; // No matching leaf found
140122
}

0 commit comments

Comments
 (0)