update search state after rebuild graph tree

This commit is contained in:
codetypes committed 2024-07-31 20:15:42 +08:00
1 parent 11b6a0b955
commit 6f4305b339
1 file changed
+16 -4
+16 -4
View File
@@ -148,7 +148,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
index: 0,
filterStr: "",
filterCase: false,
filterFocus: false,
filterFocus: true,
filterType: "content",
placeholder: "",
});
@@ -170,6 +170,16 @@ export const Editor: FC<EditorProps> = ({ 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<EditorProps> = ({ 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<EditorProps> = ({ 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<EditorProps> = ({ 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<EditorProps> = ({ onUpdate: updateState, data: editor, .
editor.graph.changeData(editor.data);
editor.graph.layout();
restoreViewport();
updateSearchState();
updateState();
}
};
@@ -1273,7 +1285,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
results: [],
index: 0,
filterCase: false,
filterFocus: false,
filterFocus: true,
filterStr: "",
filterType: "content",
placeholder: "",