@@ -18,7 +18,7 @@ import {
18
18
import type { UniqueId } from 'mo/common/types' ;
19
19
20
20
export interface IFolderTreeController extends Partial < Controller > {
21
- readonly createTreeNode ?: ( type : FileType ) => void ;
21
+ readonly createTreeNode ?: ( type : FileType , id ?: UniqueId ) => void ;
22
22
readonly onClickContextMenu ?: (
23
23
contextMenu : IMenuItemProps ,
24
24
treeNode ?: IFolderTreeNodeProps
@@ -102,14 +102,19 @@ export class FolderTreeController
102
102
} ) ;
103
103
}
104
104
105
- public createTreeNode = ( type : FileType ) => {
106
- const folderTreeState = this . folderTreeService . getState ( ) ;
107
- const { data, current } = folderTreeState ?. folderTree || { } ;
108
- // The current selected node id or the first root node
109
- const nodeId =
110
- typeof current ?. id === 'undefined' ? data ?. [ 0 ] ?. id : current ?. id ;
111
-
112
- this . emit ( FolderTreeEvent . onCreate , type , nodeId ) ;
105
+ public createTreeNode = ( type : FileType , id ?: UniqueId ) => {
106
+ if ( typeof id === 'undefined' ) {
107
+ const folderTreeState = this . folderTreeService . getState ( ) ;
108
+ const { data, current } = folderTreeState ?. folderTree || { } ;
109
+ // The current selected node id or the first root node
110
+ const nodeId =
111
+ typeof current ?. id === 'undefined'
112
+ ? data ?. [ 0 ] ?. id
113
+ : current ?. id ;
114
+ this . emit ( FolderTreeEvent . onCreate , type , nodeId ) ;
115
+ } else {
116
+ this . emit ( FolderTreeEvent . onCreate , type , id ) ;
117
+ }
113
118
} ;
114
119
115
120
public readonly onClickContextMenu = (
@@ -136,11 +141,13 @@ export class FolderTreeController
136
141
break ;
137
142
}
138
143
case NEW_FILE_COMMAND_ID : {
139
- this . createTreeNode ( FileTypes . File ) ;
144
+ const { id } = treeNode ! ;
145
+ this . createTreeNode ( FileTypes . File , id ) ;
140
146
break ;
141
147
}
142
148
case NEW_FOLDER_COMMAND_ID : {
143
- this . createTreeNode ( FileTypes . Folder ) ;
149
+ const { id } = treeNode ! ;
150
+ this . createTreeNode ( FileTypes . Folder , id ) ;
144
151
break ;
145
152
}
146
153
case OPEN_TO_SIDE_COMMAND_ID : {
0 commit comments