From 0d50a4590a47e1925574968c2cde48f4a91b59d7 Mon Sep 17 00:00:00 2001 From: George Shi Date: Thu, 9 May 2024 11:29:19 +0800 Subject: [PATCH] solve the problem of no search without collapsed --- src/components/editor.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 6244826..d593838 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -161,6 +161,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . }); if (option.results.length > 0) { const idx = option.index < option.results.length ? option.index : 0; + recursiveOpenCollapsed(option.results[idx]); editor.graph.focusItem(option.results[idx]); selectNode(option.results[idx]); } else { @@ -1079,6 +1080,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . const { results, index } = filterOption; if (results.length > 0) { const idx = (index + 1) % results.length; + recursiveOpenCollapsed(results[idx]); editor.graph.focusItem(results[idx]); selectNode(results[idx]); setFilterOption({ ...filterOption, index: idx }); @@ -1089,6 +1091,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . const { results, index } = filterOption; if (results.length > 0) { const idx = (index + results.length - 1) % results.length; + recursiveOpenCollapsed(results[idx]); editor.graph.focusItem(results[idx]); selectNode(results[idx]); setFilterOption({ ...filterOption, index: idx }); @@ -1133,6 +1136,20 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } }; + const recursiveOpenCollapsed = (id: string) => { + const recursiveFun = (searchId: string) => { + const data = findDataById(searchId); + if (searchId !== id && data.collapsed) { + data.collapsed = undefined; + } + if (data.parent) { + recursiveFun(data.parent); + } + } + recursiveFun(id); + updateGrahp(); + } + return (