define filter type
This commit is contained in:
1 parent
8b9e5b963f
commit
024f36a151
1 file changed
+19
-17
+19
-17
@@ -40,7 +40,7 @@ interface FilterOption {
|
|||||||
filterStr: string;
|
filterStr: string;
|
||||||
filterCase: boolean;
|
filterCase: boolean;
|
||||||
filterFocus: boolean;
|
filterFocus: boolean;
|
||||||
filterType: string;
|
filterType: "content" | "id";
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
workdir: useWorkspace((state) => state.workdir),
|
workdir: useWorkspace((state) => state.workdir),
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchIptRef = useRef<InputRef>(null);
|
const searchInputRef = useRef<InputRef>(null);
|
||||||
const graphRef = useRef(null);
|
const graphRef = useRef(null);
|
||||||
const sizeRef = useRef(null);
|
const sizeRef = useRef(null);
|
||||||
const editorSize = useSize(sizeRef);
|
const editorSize = useSize(sizeRef);
|
||||||
@@ -147,7 +147,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
filterType: "",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
node.highlightGray = option.filterFocus;
|
node.highlightGray = option.filterFocus;
|
||||||
if (option.filterStr) {
|
if (option.filterStr) {
|
||||||
let found = false;
|
let found = false;
|
||||||
if (option.filterType === "nodeId") {
|
if (option.filterType === "id") {
|
||||||
if (option.filterStr === node.id) {
|
if (option.filterStr === node.id) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@@ -1022,11 +1022,11 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "searchNode": {
|
case "searchNode": {
|
||||||
searchByType("");
|
searchByType("content");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "jumpNode": {
|
case "jumpNode": {
|
||||||
searchByType("nodeId");
|
searchByType("id");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "editSubtree": {
|
case "editSubtree": {
|
||||||
@@ -1093,12 +1093,12 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchByType = (type: string) => {
|
const searchByType = (type: FilterOption["filterType"]) => {
|
||||||
let placeholder = "";
|
let placeholder = "";
|
||||||
const filterType = type;
|
const filterType = type;
|
||||||
// todo multiple parameter format judgment
|
// todo multiple parameter format judgment
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "nodeId":
|
case "id":
|
||||||
placeholder = t("jumpNode");
|
placeholder = t("jumpNode");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1110,12 +1110,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
setShowingSearch(true);
|
setShowingSearch(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (filterOption.filterType === type) return searchIptRef.current?.focus();
|
if (filterOption.filterType === type) {
|
||||||
|
return searchInputRef.current?.focus();
|
||||||
|
}
|
||||||
setShowingSearch(false);
|
setShowingSearch(false);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setShowingSearch(true);
|
setShowingSearch(true);
|
||||||
setFilterOption({ ...filterOption, placeholder, filterType });
|
setFilterOption({ ...filterOption, placeholder, filterType });
|
||||||
searchIptRef.current?.focus();
|
searchInputRef.current?.focus();
|
||||||
}, 50);
|
}, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1123,9 +1125,9 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
if (e.code === Hotkey.Enter) {
|
if (e.code === Hotkey.Enter) {
|
||||||
nextResult();
|
nextResult();
|
||||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
||||||
searchByType("");
|
searchByType("content");
|
||||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
||||||
searchByType("nodeId");
|
searchByType("id");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1158,7 +1160,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
ref={searchIptRef}
|
ref={searchInputRef}
|
||||||
placeholder={filterOption.placeholder}
|
placeholder={filterOption.placeholder}
|
||||||
autoFocus
|
autoFocus
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1178,7 +1180,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
suffix={
|
suffix={
|
||||||
<Flex gap="2px" style={{ alignItems: "center" }}>
|
<Flex gap="2px" style={{ alignItems: "center" }}>
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1218,7 +1220,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
? `${filterOption.index + 1}/${filterOption.results.length}`
|
? `${filterOption.index + 1}/${filterOption.results.length}`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowDownOutlined />}
|
icon={<ArrowDownOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1228,7 +1230,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
onClick={nextResult}
|
onClick={nextResult}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowUpOutlined />}
|
icon={<ArrowUpOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1251,7 +1253,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterType: "",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
});
|
});
|
||||||
keysRef.current?.focus();
|
keysRef.current?.focus();
|
||||||
|
|||||||
Reference in new issue
Block a user