In my plugin, in the nav tree, in some scenarios, I put the MD file HTML element inside the folder HTML element. However, when I right-click on the MD file element, it propagates and triggers the folder’s ‘context-menu’. I used this script to fix it, But I lost the original MD file’s ‘context-menu’ features like rename or delete.
toMove.addEventListener("contextmenu", (e) => {
e.stopPropagation(); // Prevent event from bubbling up
e.preventDefault(); // Prevent the browser's default context menu
const file = plugin.app.vault.getAbstractFileByPath(dataPath as string);
if (file instanceof TFile) {
// Create a new Menu object
const menu = new Menu();
// Trigger the 'file-menu' event
//@ts-ignore
plugin.app.workspace.trigger("file-menu", menu, file, "file-explorer");
// Show the menu at the mouse position
menu.showAtMouseEvent(e);
}
});
How to trigger the original file’s menu , or how to trigger proper TFile file-menu menu ?