Skip to content

Commit 14c6057

Browse files
authored
fix: fix create file node incorrect on contextMenu (#522)
1 parent 2503f4a commit 14c6057

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/controller/explorer/folderTree.tsx

+18-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import type { UniqueId } from 'mo/common/types';
1919

2020
export interface IFolderTreeController extends Partial<Controller> {
21-
readonly createTreeNode?: (type: FileType) => void;
21+
readonly createTreeNode?: (type: FileType, id?: UniqueId) => void;
2222
readonly onClickContextMenu?: (
2323
contextMenu: IMenuItemProps,
2424
treeNode?: IFolderTreeNodeProps
@@ -102,14 +102,19 @@ export class FolderTreeController
102102
});
103103
}
104104

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+
}
113118
};
114119

115120
public readonly onClickContextMenu = (
@@ -136,11 +141,13 @@ export class FolderTreeController
136141
break;
137142
}
138143
case NEW_FILE_COMMAND_ID: {
139-
this.createTreeNode(FileTypes.File);
144+
const { id } = treeNode!;
145+
this.createTreeNode(FileTypes.File, id);
140146
break;
141147
}
142148
case NEW_FOLDER_COMMAND_ID: {
143-
this.createTreeNode(FileTypes.Folder);
149+
const { id } = treeNode!;
150+
this.createTreeNode(FileTypes.Folder, id);
144151
break;
145152
}
146153
case OPEN_TO_SIDE_COMMAND_ID: {

0 commit comments

Comments
 (0)