select the editing node when jump from edit subtree

This commit is contained in:
codetypes committed 2024-11-25 20:46:30 +08:00
1 parent 734879a736
commit c933541f3e
5 files changed
+27 -15

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "behavior3editor",
"version": "1.6.0",
"version": "1.7.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "behavior3editor",
"version": "1.6.0",
"version": "1.7.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "behavior3editor",
"version": "1.6.0",
"version": "1.7.0",
"main": "dist-electron/main/index.js",
"description": "行为树编辑器",
"author": "zhandouxiaojiji & codetypes",
+10 -1
View File
@@ -660,7 +660,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
const data = findSubtree(findDataById(editor.selectedId));
if (data?.path) {
const path = `${workspace.workdir}/${data.path}`;
workspace.open(path);
workspace.open(path, Number(editor.selectedId) - Number(data.id) + 1);
}
};
@@ -1075,6 +1075,15 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
editor.size.width = editorSize.width;
editor.size.height = editorSize.height;
}
if (typeof editor.editNode === "number") {
const id = editor.editNode.toString();
selectNode(null);
setTimeout(() => {
editor.graph.focusItem(id);
selectNode(id);
}, 100);
}
});
// check should subtree
+13 -10
View File
@@ -61,7 +61,7 @@ export class EditorStore {
graphMatrix?: Matrix;
graph!: TreeGraph;
editNode: EditNode | null = null;
editNode: EditNode | number | null = null;
dispatch!: (event: EditEvent, data?: unknown) => void;
@@ -139,8 +139,8 @@ export type WorkspaceStore = {
isShowingSearch: boolean;
onShowingSearch: (isShowingSearch: boolean) => void;
open: (path: string) => void;
edit: (path: string) => void;
open: (path: string, selectedNode?: number) => void;
edit: (path: string, selectedNode?: number) => void;
close: (path: string) => void;
find: (path: string) => EditorStore | undefined;
relative: (path: string) => string;
@@ -402,7 +402,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
set({ isShowingSearch });
},
open: (path) => {
open: (path, selectedNode) => {
path = fs.realpathSync(path);
const workspace = get();
let editor = workspace.editors.find((v) => v.path === path);
@@ -412,25 +412,28 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
workspace.editors.push(editor);
set({ editors: workspace.editors });
workspace.updateFileMeta(editor);
workspace.edit(editor.path);
workspace.edit(editor.path, selectedNode);
} catch (error) {
console.error(error);
message.error(`invalid file: ${path}`);
}
} else if (workspace.editing !== editor) {
workspace.edit(editor.path);
workspace.edit(editor.path, selectedNode);
}
},
edit: (path) => {
edit: (path, selectedNode) => {
const workspace = get();
const editor = workspace.editors.find((v) => v.path === path);
if (editor && selectedNode) {
editor.editNode = selectedNode;
}
set({ editing: editor, editingNode: null, editingTree: null });
if (editor) {
if (editor.editNode) {
workspace.onEditingNode(editor.editNode);
} else {
if (!editor.editNode) {
workspace.onEditingTree(editor);
} else if (typeof editor.editNode === "object") {
workspace.onEditingNode(editor.editNode);
}
} else {
set({ editingNode: null, editingTree: null });