From 6f4305b339fbdc0510afc923475e5c9248a4fb49 Mon Sep 17 00:00:00 2001 From: codetypes Date: Wed, 31 Jul 2024 20:15:42 +0800 Subject: [PATCH] update search state after rebuild graph tree --- src/components/editor.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 32d3ddc..c4e6f9f 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -148,7 +148,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . index: 0, filterStr: "", filterCase: false, - filterFocus: false, + filterFocus: true, filterType: "content", placeholder: "", }); @@ -170,6 +170,16 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . editor.graph.findAll("node", () => true).forEach((item) => item.draw()); }; + const updateSearchState = () => { + const option = { ...filterOption }; + option.results.length = 0; + filterNodes(option, findDataById("1")); + setFilterOption({ + ...option, + }); + editor.graph.findAll("node", () => true).forEach((item) => item.draw()); + }; + const onDebounceSearchChange = useDebounceCallback(onSearchChange, 200); const onChange = () => { @@ -236,7 +246,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . const filterNodes = (option: FilterOption, node: TreeGraphData | null) => { if (node) { - node.highlightGray = option.filterFocus; + node.highlightGray = option.filterFocus && !!option.filterStr; if (option.filterStr) { let found = false; if (option.filterType === "id") { @@ -577,6 +587,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . if (editor.historyIndex > 0) { const data = editor.historyStack[--editor.historyIndex]; useStackData(data); + updateSearchState(); } }; @@ -584,6 +595,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . if (editor.historyIndex < editor.historyStack.length - 1) { const data = editor.historyStack[++editor.historyIndex]; useStackData(data); + updateSearchState(); } }; @@ -613,7 +625,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . editor.graph.changeData(editor.data); editor.graph.layout(); restoreViewport(); - + updateSearchState(); updateState(); } }; @@ -1273,7 +1285,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . results: [], index: 0, filterCase: false, - filterFocus: false, + filterFocus: true, filterStr: "", filterType: "content", placeholder: "",