From cdff7554559326dfe948dc2e14212c88293db8a2 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Mon, 18 Aug 2025 15:13:32 +0800 Subject: [PATCH] Add `items` parameter to the `open-menu-doctree` event --- app/src/menus/navigation.ts | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index 9868879303f..9170ff24c98 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -31,22 +31,28 @@ import {emitOpenMenu} from "../plugin/EventBus"; import {openByMobile} from "../protyle/util/compatibility"; import {addFilesToDatabase} from "../protyle/render/av/addToDatabase"; -const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { - const fileItemElement = Array.from(selectItemElements).find(item => { - if (item.getAttribute("data-type") === "navigation-file") { - return true; - } - }); - if (!fileItemElement) { - return window.siyuan.menus.menu; - } +const initMultiMenu = (selectItemElements: Element[], app: App) => { + const items: { id: string, path: string }[] = []; const blockIDs: string[] = []; - selectItemElements.forEach(item => { + const fileItemElements = selectItemElements.filter(item => { + if (item.getAttribute("data-type") === "navigation-file") { const id = item.getAttribute("data-node-id"); - if (id) { + const path = item.getAttribute("data-path"); + if (id && path) { + items.push({ + id: id, + path: path, + }); blockIDs.push(id); } + return true; + } + return false; }); + + if (fileItemElements.length === 0) { + return window.siyuan.menus.menu; + } if (blockIDs.length > 0) { window.siyuan.menus.menu.append(new MenuItem({ @@ -69,11 +75,7 @@ const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { }]) }).element); } - - window.siyuan.menus.menu.append(movePathToMenu(getTopPaths( - Array.from(selectItemElements) - ))); - + window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(fileItemElements))); if (blockIDs.length > 0) { window.siyuan.menus.menu.append(new MenuItem({ id: "addToDatabase", @@ -81,7 +83,7 @@ const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, icon: "iconDatabase", click: () => { - addFilesToDatabase(Array.from(selectItemElements)); + addFilesToDatabase(fileItemElements); } }).element); } @@ -91,13 +93,14 @@ const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { label: window.siyuan.languages.delete, accelerator: "⌦", click: () => { - deleteFiles(Array.from(selectItemElements)); + deleteFiles(fileItemElements); } }).element); if (blockIDs.length === 0) { return window.siyuan.menus.menu; } + window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element); if (!window.siyuan.config.readonly) { const riffCardMenu = [{ @@ -176,8 +179,9 @@ const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { plugins: app.plugins, type: "open-menu-doctree", detail: { - elements: selectItemElements, - type: "docs" + elements: fileItemElements, + type: "docs", + items, }, separatorPosition: "top", }); @@ -199,7 +203,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => { }); liElement.classList.add("b3-list-item--focus"); } - const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus"); + const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus")); if (selectItemElements.length > 1) { return initMultiMenu(selectItemElements, app); } @@ -407,7 +411,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => { type: "open-menu-doctree", detail: { elements: selectItemElements, - type: "notebook" + type: "notebook", + items: [{id: notebookId, path: "/"}], }, separatorPosition: "top", }); @@ -429,11 +434,12 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l }); liElement.classList.add("b3-list-item--focus"); } - const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus"); + const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus")); if (selectItemElements.length > 1) { return initMultiMenu(selectItemElements, app); } const id = liElement.getAttribute("data-node-id"); + const path = liElement.getAttribute("data-path"); let name = liElement.getAttribute("data-name"); name = getDisplayName(name, false, true); if (!window.siyuan.config.readonly) { @@ -701,7 +707,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l type: "open-menu-doctree", detail: { elements: selectItemElements, - type: "doc" + type: "doc", + items: [{id, path}], }, separatorPosition: "top", });