From 024f36a15191a7656eff88539467e1c3a82929c4 Mon Sep 17 00:00:00 2001 From: codetypes Date: Tue, 30 Apr 2024 17:36:03 +0800 Subject: [PATCH] define filter type --- src/components/editor.tsx | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 7b36c52..1cf1e60 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -40,7 +40,7 @@ interface FilterOption { filterStr: string; filterCase: boolean; filterFocus: boolean; - filterType: string; + filterType: "content" | "id"; placeholder: string; } @@ -133,7 +133,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . workdir: useWorkspace((state) => state.workdir), }; - const searchIptRef = useRef(null); + const searchInputRef = useRef(null); const graphRef = useRef(null); const sizeRef = useRef(null); const editorSize = useSize(sizeRef); @@ -147,7 +147,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . filterStr: "", filterCase: false, filterFocus: false, - filterType: "", + filterType: "content", placeholder: "", }); @@ -236,7 +236,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . node.highlightGray = option.filterFocus; if (option.filterStr) { let found = false; - if (option.filterType === "nodeId") { + if (option.filterType === "id") { if (option.filterStr === node.id) { found = true; } @@ -1022,11 +1022,11 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . break; } case "searchNode": { - searchByType(""); + searchByType("content"); break; } case "jumpNode": { - searchByType("nodeId"); + searchByType("id"); break; } case "editSubtree": { @@ -1093,12 +1093,12 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } }; - const searchByType = (type: string) => { + const searchByType = (type: FilterOption["filterType"]) => { let placeholder = ""; const filterType = type; // todo multiple parameter format judgment switch (type) { - case "nodeId": + case "id": placeholder = t("jumpNode"); break; default: @@ -1110,12 +1110,14 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . setShowingSearch(true); return; } - if (filterOption.filterType === type) return searchIptRef.current?.focus(); + if (filterOption.filterType === type) { + return searchInputRef.current?.focus(); + } setShowingSearch(false); setTimeout(() => { setShowingSearch(true); setFilterOption({ ...filterOption, placeholder, filterType }); - searchIptRef.current?.focus(); + searchInputRef.current?.focus(); }, 50); }; @@ -1123,9 +1125,9 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . if (e.code === Hotkey.Enter) { nextResult(); } else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") { - searchByType(""); + searchByType("content"); } else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") { - searchByType("nodeId"); + searchByType("id"); } }; @@ -1158,7 +1160,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . }} > = ({ onUpdate: updateState, data: editor, . onKeyDown={handleKeyDown} suffix={ - {filterOption.filterType !== "nodeId" && ( + {filterOption.filterType !== "id" && (