format code
This commit is contained in:
1 parent
d32c457990
commit
8b9e5b963f
6 files changed
+61
-52
No files matched your search
+31
-28
@@ -11,6 +11,7 @@ import { message } from "@/misc/hooks";
|
||||
import i18n from "@/misc/i18n";
|
||||
import { Hotkey, isHotkeyPressed, isMacos, useHotkeys } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { mergeClassNames } from "@/misc/util";
|
||||
import { ArrowDownOutlined, ArrowUpOutlined, CloseOutlined } from "@ant-design/icons";
|
||||
import G6, { G6GraphEvent, Item, TreeGraph } from "@antv/g6";
|
||||
import { dialog } from "@electron/remote";
|
||||
@@ -18,7 +19,7 @@ import { useSize } from "ahooks";
|
||||
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
||||
import { clipboard } from "electron";
|
||||
import * as fs from "fs";
|
||||
import React, { FC, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import React, { FC, KeyboardEvent, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FiDelete } from "react-icons/fi";
|
||||
import { IoMdReturnLeft } from "react-icons/io";
|
||||
@@ -27,7 +28,6 @@ import { VscCaseSensitive } from "react-icons/vsc";
|
||||
import { mergeRefs } from "react-merge-refs";
|
||||
import { useDebounceCallback } from "usehooks-ts";
|
||||
import "./register-node";
|
||||
import { mergeClassNames } from "@/misc/util";
|
||||
|
||||
export interface EditorProps extends React.HTMLAttributes<HTMLElement> {
|
||||
data: EditorStore;
|
||||
@@ -148,7 +148,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
filterCase: false,
|
||||
filterFocus: false,
|
||||
filterType: "",
|
||||
placeholder: ""
|
||||
placeholder: "",
|
||||
});
|
||||
|
||||
const onSearchChange = (option: FilterOption) => {
|
||||
@@ -238,10 +238,13 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
let found = false;
|
||||
if (option.filterType === "nodeId") {
|
||||
if (option.filterStr === node.id) {
|
||||
found = true
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if (includeString(node.name, option) || includeString(node.desc || node.def.desc, option)) {
|
||||
if (
|
||||
includeString(node.name, option) ||
|
||||
includeString(node.desc || node.def.desc, option)
|
||||
) {
|
||||
found = true;
|
||||
} else if (node.input) {
|
||||
for (const str of node.input) {
|
||||
@@ -1091,40 +1094,40 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
};
|
||||
|
||||
const searchByType = (type: string) => {
|
||||
let placeholder = ""
|
||||
const filterType = type
|
||||
let placeholder = "";
|
||||
const filterType = type;
|
||||
// todo multiple parameter format judgment
|
||||
switch (type) {
|
||||
case "nodeId":
|
||||
placeholder = t("jumpNode")
|
||||
break
|
||||
placeholder = t("jumpNode");
|
||||
break;
|
||||
default:
|
||||
placeholder = t("searchNode")
|
||||
break
|
||||
placeholder = t("searchNode");
|
||||
break;
|
||||
}
|
||||
if (!showingSearch) {
|
||||
setFilterOption({ ...filterOption, placeholder, filterType })
|
||||
setShowingSearch(true)
|
||||
return
|
||||
setFilterOption({ ...filterOption, placeholder, filterType });
|
||||
setShowingSearch(true);
|
||||
return;
|
||||
}
|
||||
if (filterOption.filterType === type) return searchIptRef.current?.focus()
|
||||
setShowingSearch(false)
|
||||
if (filterOption.filterType === type) return searchIptRef.current?.focus();
|
||||
setShowingSearch(false);
|
||||
setTimeout(() => {
|
||||
setShowingSearch(true)
|
||||
setFilterOption({ ...filterOption, placeholder, filterType })
|
||||
searchIptRef.current?.focus()
|
||||
}, 50)
|
||||
}
|
||||
setShowingSearch(true);
|
||||
setFilterOption({ ...filterOption, placeholder, filterType });
|
||||
searchIptRef.current?.focus();
|
||||
}, 50);
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.code === Hotkey.Enter) {
|
||||
nextResult()
|
||||
nextResult();
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
||||
searchByType("")
|
||||
searchByType("");
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
||||
searchByType("nodeId")
|
||||
searchByType("nodeId");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -1156,7 +1159,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
>
|
||||
<Input
|
||||
ref={searchIptRef}
|
||||
placeholder={ filterOption.placeholder }
|
||||
placeholder={filterOption.placeholder}
|
||||
autoFocus
|
||||
size="small"
|
||||
style={{
|
||||
@@ -1172,7 +1175,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
index: 0,
|
||||
})
|
||||
}
|
||||
onKeyDown={ handleKeyDown }
|
||||
onKeyDown={handleKeyDown}
|
||||
suffix={
|
||||
<Flex gap="2px" style={{ alignItems: "center" }}>
|
||||
{filterOption.filterType !== "nodeId" && (
|
||||
@@ -1249,7 +1252,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
filterFocus: false,
|
||||
filterStr: "",
|
||||
filterType: "",
|
||||
placeholder: ""
|
||||
placeholder: "",
|
||||
});
|
||||
keysRef.current?.focus();
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user