@@ -31,22 +31,28 @@ import {emitOpenMenu} from "../plugin/EventBus";
31
31
import { openByMobile } from "../protyle/util/compatibility" ;
32
32
import { addFilesToDatabase } from "../protyle/render/av/addToDatabase" ;
33
33
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 } [ ] = [ ] ;
43
36
const blockIDs : string [ ] = [ ] ;
44
- selectItemElements . forEach ( item => {
37
+ const fileItemElements = selectItemElements . filter ( item => {
38
+ if ( item . getAttribute ( "data-type" ) === "navigation-file" ) {
45
39
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
+ } ) ;
47
46
blockIDs . push ( id ) ;
48
47
}
48
+ return true ;
49
+ }
50
+ return false ;
49
51
} ) ;
52
+
53
+ if ( fileItemElements . length === 0 ) {
54
+ return window . siyuan . menus . menu ;
55
+ }
50
56
51
57
if ( blockIDs . length > 0 ) {
52
58
window . siyuan . menus . menu . append ( new MenuItem ( {
@@ -69,19 +75,15 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
69
75
} ] )
70
76
} ) . element ) ;
71
77
}
72
-
73
- window . siyuan . menus . menu . append ( movePathToMenu ( getTopPaths (
74
- Array . from ( selectItemElements )
75
- ) ) ) ;
76
-
78
+ window . siyuan . menus . menu . append ( movePathToMenu ( getTopPaths ( fileItemElements ) ) ) ;
77
79
if ( blockIDs . length > 0 ) {
78
80
window . siyuan . menus . menu . append ( new MenuItem ( {
79
81
id : "addToDatabase" ,
80
82
label : window . siyuan . languages . addToDatabase ,
81
83
accelerator : window . siyuan . config . keymap . general . addToDatabase . custom ,
82
84
icon : "iconDatabase" ,
83
85
click : ( ) => {
84
- addFilesToDatabase ( Array . from ( selectItemElements ) ) ;
86
+ addFilesToDatabase ( fileItemElements ) ;
85
87
}
86
88
} ) . element ) ;
87
89
}
@@ -91,13 +93,14 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
91
93
label : window . siyuan . languages . delete ,
92
94
accelerator : "⌦" ,
93
95
click : ( ) => {
94
- deleteFiles ( Array . from ( selectItemElements ) ) ;
96
+ deleteFiles ( fileItemElements ) ;
95
97
}
96
98
} ) . element ) ;
97
99
98
100
if ( blockIDs . length === 0 ) {
99
101
return window . siyuan . menus . menu ;
100
102
}
103
+
101
104
window . siyuan . menus . menu . append ( new MenuItem ( { id : "separator_1" , type : "separator" } ) . element ) ;
102
105
if ( ! window . siyuan . config . readonly ) {
103
106
const riffCardMenu = [ {
@@ -176,8 +179,9 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
176
179
plugins : app . plugins ,
177
180
type : "open-menu-doctree" ,
178
181
detail : {
179
- elements : selectItemElements ,
180
- type : "docs"
182
+ elements : fileItemElements ,
183
+ type : "docs" ,
184
+ items,
181
185
} ,
182
186
separatorPosition : "top" ,
183
187
} ) ;
@@ -199,7 +203,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
199
203
} ) ;
200
204
liElement . classList . add ( "b3-list-item--focus" ) ;
201
205
}
202
- const selectItemElements = fileElement . querySelectorAll ( ".b3-list-item--focus" ) ;
206
+ const selectItemElements = Array . from ( fileElement . querySelectorAll ( ".b3-list-item--focus" ) ) ;
203
207
if ( selectItemElements . length > 1 ) {
204
208
return initMultiMenu ( selectItemElements , app ) ;
205
209
}
@@ -407,7 +411,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
407
411
type : "open-menu-doctree" ,
408
412
detail : {
409
413
elements : selectItemElements ,
410
- type : "notebook"
414
+ type : "notebook" ,
415
+ items : [ { id : notebookId , path : "/" } ] ,
411
416
} ,
412
417
separatorPosition : "top" ,
413
418
} ) ;
@@ -429,11 +434,12 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
429
434
} ) ;
430
435
liElement . classList . add ( "b3-list-item--focus" ) ;
431
436
}
432
- const selectItemElements = fileElement . querySelectorAll ( ".b3-list-item--focus" ) ;
437
+ const selectItemElements = Array . from ( fileElement . querySelectorAll ( ".b3-list-item--focus" ) ) ;
433
438
if ( selectItemElements . length > 1 ) {
434
439
return initMultiMenu ( selectItemElements , app ) ;
435
440
}
436
441
const id = liElement . getAttribute ( "data-node-id" ) ;
442
+ const path = liElement . getAttribute ( "data-path" ) ;
437
443
let name = liElement . getAttribute ( "data-name" ) ;
438
444
name = getDisplayName ( name , false , true ) ;
439
445
if ( ! window . siyuan . config . readonly ) {
@@ -701,7 +707,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
701
707
type : "open-menu-doctree" ,
702
708
detail : {
703
709
elements : selectItemElements ,
704
- type : "doc"
710
+ type : "doc" ,
711
+ items : [ { id, path} ] ,
705
712
} ,
706
713
separatorPosition : "top" ,
707
714
} ) ;
0 commit comments