Skip to content

Commit cdff755

Browse files
committed
Add items parameter to the open-menu-doctree event
1 parent f1c9186 commit cdff755

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

app/src/menus/navigation.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ import {emitOpenMenu} from "../plugin/EventBus";
3131
import {openByMobile} from "../protyle/util/compatibility";
3232
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
3333

34-
const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
35-
const fileItemElement = Array.from(selectItemElements).find(item => {
36-
if (item.getAttribute("data-type") === "navigation-file") {
37-
return true;
38-
}
39-
});
40-
if (!fileItemElement) {
41-
return window.siyuan.menus.menu;
42-
}
34+
const initMultiMenu = (selectItemElements: Element[], app: App) => {
35+
const items: { id: string, path: string }[] = [];
4336
const blockIDs: string[] = [];
44-
selectItemElements.forEach(item => {
37+
const fileItemElements = selectItemElements.filter(item => {
38+
if (item.getAttribute("data-type") === "navigation-file") {
4539
const id = item.getAttribute("data-node-id");
46-
if (id) {
40+
const path = item.getAttribute("data-path");
41+
if (id && path) {
42+
items.push({
43+
id: id,
44+
path: path,
45+
});
4746
blockIDs.push(id);
4847
}
48+
return true;
49+
}
50+
return false;
4951
});
52+
53+
if (fileItemElements.length === 0) {
54+
return window.siyuan.menus.menu;
55+
}
5056

5157
if (blockIDs.length > 0) {
5258
window.siyuan.menus.menu.append(new MenuItem({
@@ -69,19 +75,15 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
6975
}])
7076
}).element);
7177
}
72-
73-
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
74-
Array.from(selectItemElements)
75-
)));
76-
78+
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(fileItemElements)));
7779
if (blockIDs.length > 0) {
7880
window.siyuan.menus.menu.append(new MenuItem({
7981
id: "addToDatabase",
8082
label: window.siyuan.languages.addToDatabase,
8183
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
8284
icon: "iconDatabase",
8385
click: () => {
84-
addFilesToDatabase(Array.from(selectItemElements));
86+
addFilesToDatabase(fileItemElements);
8587
}
8688
}).element);
8789
}
@@ -91,13 +93,14 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
9193
label: window.siyuan.languages.delete,
9294
accelerator: "⌦",
9395
click: () => {
94-
deleteFiles(Array.from(selectItemElements));
96+
deleteFiles(fileItemElements);
9597
}
9698
}).element);
9799

98100
if (blockIDs.length === 0) {
99101
return window.siyuan.menus.menu;
100102
}
103+
101104
window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);
102105
if (!window.siyuan.config.readonly) {
103106
const riffCardMenu = [{
@@ -176,8 +179,9 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
176179
plugins: app.plugins,
177180
type: "open-menu-doctree",
178181
detail: {
179-
elements: selectItemElements,
180-
type: "docs"
182+
elements: fileItemElements,
183+
type: "docs",
184+
items,
181185
},
182186
separatorPosition: "top",
183187
});
@@ -199,7 +203,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
199203
});
200204
liElement.classList.add("b3-list-item--focus");
201205
}
202-
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
206+
const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
203207
if (selectItemElements.length > 1) {
204208
return initMultiMenu(selectItemElements, app);
205209
}
@@ -407,7 +411,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
407411
type: "open-menu-doctree",
408412
detail: {
409413
elements: selectItemElements,
410-
type: "notebook"
414+
type: "notebook",
415+
items: [{id: notebookId, path: "/"}],
411416
},
412417
separatorPosition: "top",
413418
});
@@ -429,11 +434,12 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
429434
});
430435
liElement.classList.add("b3-list-item--focus");
431436
}
432-
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
437+
const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
433438
if (selectItemElements.length > 1) {
434439
return initMultiMenu(selectItemElements, app);
435440
}
436441
const id = liElement.getAttribute("data-node-id");
442+
const path = liElement.getAttribute("data-path");
437443
let name = liElement.getAttribute("data-name");
438444
name = getDisplayName(name, false, true);
439445
if (!window.siyuan.config.readonly) {
@@ -701,7 +707,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
701707
type: "open-menu-doctree",
702708
detail: {
703709
elements: selectItemElements,
704-
type: "doc"
710+
type: "doc",
711+
items: [{id, path}],
705712
},
706713
separatorPosition: "top",
707714
});

0 commit comments

Comments
 (0)