From 03f33cc0a94684b58934a4444914afca37af1ab2 Mon Sep 17 00:00:00 2001 From: liaibo Date: Sun, 28 Dec 2025 22:13:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(mindmap):=20=E8=A1=A5=E5=85=A8=20ensureActi?= =?UTF-8?q?veBefore=20=E9=98=B2=E6=AD=A2=E5=B7=A5=E5=85=B7=E6=A0=8F?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/editor/blocks/MindmapBlock.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx b/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx index 741a4c7d..3042fa72 100644 --- a/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx +++ b/wolai-frontend/src/components/editor/blocks/MindmapBlock.tsx @@ -82,6 +82,26 @@ const applyToActiveNodes = ( (mindmap.renderer?.activeNodeList ?? []).forEach(handler); }; +// 确保存在激活节点后再执行命令,若无则自动选中根节点 +const ensureActiveBefore = (mindmap?: MindMapInstance | null) => { + const mm = mindmap ?? null; + if (!mm) { + window.alert("思维导图尚未初始化"); + return null; + } + const list = mm.renderer?.activeNodeList ?? []; + if (!list || list.length === 0) { + const root = mm.renderer?.root ?? mm.renderer?.renderTree?._node; + if (root) { + mm.execCommand?.("SET_NODE_ACTIVE", root, true); + } else { + window.alert("请先选中一个节点"); + return null; + } + } + return mm; +}; + const MindmapBlockView = ({ block, editor,