From c933541f3e7aaad76e391c5258435c19fe8c8373 Mon Sep 17 00:00:00 2001 From: codetypes Date: Mon, 25 Nov 2024 20:46:30 +0800 Subject: [PATCH] select the editing node when jump from edit subtree --- package-lock.json | 4 ++-- package.json | 2 +- src/behavior3 | 2 +- src/components/editor.tsx | 11 ++++++++++- src/contexts/workspace-context.ts | 23 +++++++++++++---------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8fdc257..e772fbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index d3eb6e2..9b8733d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "behavior3editor", - "version": "1.6.0", + "version": "1.7.0", "main": "dist-electron/main/index.js", "description": "行为树编辑器", "author": "zhandouxiaojiji & codetypes", diff --git a/src/behavior3 b/src/behavior3 index a7868c4..06a5db5 160000 --- a/src/behavior3 +++ b/src/behavior3 @@ -1 +1 @@ -Subproject commit a7868c472171c7aba4beef7096e84d87f1d2388d +Subproject commit 06a5db59896bdfcb5f2ff449e01505a3e5293dd6 diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 24e199c..a57619c 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -660,7 +660,7 @@ export const Editor: FC = ({ 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 = ({ 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 diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index 2394381..fd9780e 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -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((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((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 });