Merge pull request #22 from GeorgeShiZZZ/master
add ctrl/command + g to jump node by id
This commit is contained in:
6 files changed
+78
-7
No files matched your search
@@ -19,6 +19,7 @@
|
|||||||
"hide": "Hide Behavior3",
|
"hide": "Hide Behavior3",
|
||||||
"hideOthers": "Hide Others",
|
"hideOthers": "Hide Others",
|
||||||
"insertNode": "Insert Node",
|
"insertNode": "Insert Node",
|
||||||
|
"jumpNode": "Jump Node",
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
"moveToTrash": "Move to Trash",
|
"moveToTrash": "Move to Trash",
|
||||||
"newFile": "New File...",
|
"newFile": "New File...",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"hide": "隐藏 Behavior3",
|
"hide": "隐藏 Behavior3",
|
||||||
"hideOthers": "隐藏其它",
|
"hideOthers": "隐藏其它",
|
||||||
"insertNode": "插入节点",
|
"insertNode": "插入节点",
|
||||||
|
"jumpNode": "跳转节点",
|
||||||
"language": "语言",
|
"language": "语言",
|
||||||
"moveToTrash": "移至回收站",
|
"moveToTrash": "移至回收站",
|
||||||
"newFile": "新建行为树...",
|
"newFile": "新建行为树...",
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import { ArrowDownOutlined, ArrowUpOutlined, CloseOutlined } from "@ant-design/i
|
|||||||
import G6, { G6GraphEvent, Item, TreeGraph } from "@antv/g6";
|
import G6, { G6GraphEvent, Item, TreeGraph } from "@antv/g6";
|
||||||
import { dialog } from "@electron/remote";
|
import { dialog } from "@electron/remote";
|
||||||
import { useSize } from "ahooks";
|
import { useSize } from "ahooks";
|
||||||
import { Button, Dropdown, Flex, FlexProps, Input, MenuProps } from "antd";
|
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
||||||
import { clipboard } from "electron";
|
import { clipboard } from "electron";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import React, { FC, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FiDelete } from "react-icons/fi";
|
import { FiDelete } from "react-icons/fi";
|
||||||
import { IoMdReturnLeft } from "react-icons/io";
|
import { IoMdReturnLeft } from "react-icons/io";
|
||||||
@@ -40,6 +40,8 @@ interface FilterOption {
|
|||||||
filterStr: string;
|
filterStr: string;
|
||||||
filterCase: boolean;
|
filterCase: boolean;
|
||||||
filterFocus: boolean;
|
filterFocus: boolean;
|
||||||
|
filterType: string;
|
||||||
|
placeholder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createMenu = () => {
|
const createMenu = () => {
|
||||||
@@ -131,6 +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 graphRef = useRef(null);
|
const graphRef = useRef(null);
|
||||||
const sizeRef = useRef(null);
|
const sizeRef = useRef(null);
|
||||||
const editorSize = useSize(sizeRef);
|
const editorSize = useSize(sizeRef);
|
||||||
@@ -144,6 +147,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
|
filterType: "",
|
||||||
|
placeholder: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSearchChange = (option: FilterOption) => {
|
const onSearchChange = (option: FilterOption) => {
|
||||||
@@ -231,6 +236,11 @@ 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.filterStr === node.id) {
|
||||||
|
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;
|
found = true;
|
||||||
} else if (node.input) {
|
} else if (node.input) {
|
||||||
@@ -259,6 +269,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
option.results.push(node.id);
|
option.results.push(node.id);
|
||||||
node.highlightGray = false;
|
node.highlightGray = false;
|
||||||
@@ -1008,7 +1019,11 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "searchNode": {
|
case "searchNode": {
|
||||||
setShowingSearch(true);
|
searchByType("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "jumpNode": {
|
||||||
|
searchByType("nodeId");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "editSubtree": {
|
case "editSubtree": {
|
||||||
@@ -1075,6 +1090,42 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const searchByType = (type: string) => {
|
||||||
|
let placeholder = ""
|
||||||
|
const filterType = type
|
||||||
|
// todo multiple parameter format judgment
|
||||||
|
switch (type) {
|
||||||
|
case "nodeId":
|
||||||
|
placeholder = t("jumpNode")
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
placeholder = t("searchNode")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (!showingSearch) {
|
||||||
|
setFilterOption({ ...filterOption, placeholder, filterType })
|
||||||
|
setShowingSearch(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (filterOption.filterType === type) return searchIptRef.current?.focus()
|
||||||
|
setShowingSearch(false)
|
||||||
|
setTimeout(() => {
|
||||||
|
setShowingSearch(true)
|
||||||
|
setFilterOption({ ...filterOption, placeholder, filterType })
|
||||||
|
searchIptRef.current?.focus()
|
||||||
|
}, 50)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.code === Hotkey.Enter) {
|
||||||
|
nextResult()
|
||||||
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
||||||
|
searchByType("")
|
||||||
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
||||||
|
searchByType("nodeId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
{...props}
|
{...props}
|
||||||
@@ -1104,6 +1155,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
|
ref={searchIptRef}
|
||||||
|
placeholder={ filterOption.placeholder }
|
||||||
autoFocus
|
autoFocus
|
||||||
size="small"
|
size="small"
|
||||||
style={{
|
style={{
|
||||||
@@ -1119,9 +1172,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
index: 0,
|
index: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onKeyDown={(e) => e.code === Hotkey.Enter && nextResult()}
|
onKeyDown={ handleKeyDown }
|
||||||
suffix={
|
suffix={
|
||||||
<Flex gap="2px" style={{ alignItems: "center" }}>
|
<Flex gap="2px" style={{ alignItems: "center" }}>
|
||||||
|
{filterOption.filterType !== "nodeId" && (
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1137,6 +1191,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1160,6 +1215,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" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowDownOutlined />}
|
icon={<ArrowDownOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1168,6 +1224,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
disabled={filterOption.results.length == 0}
|
disabled={filterOption.results.length == 0}
|
||||||
onClick={nextResult}
|
onClick={nextResult}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{filterOption.filterType !== "nodeId" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowUpOutlined />}
|
icon={<ArrowUpOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1176,6 +1234,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
disabled={filterOption.results.length == 0}
|
disabled={filterOption.results.length == 0}
|
||||||
onClick={prevResult}
|
onClick={prevResult}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
icon={<CloseOutlined />}
|
icon={<CloseOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1189,6 +1248,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
filterStr: "",
|
filterStr: "",
|
||||||
|
filterType: "",
|
||||||
|
placeholder: ""
|
||||||
});
|
});
|
||||||
keysRef.current?.focus();
|
keysRef.current?.focus();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const Workspace: FC = () => {
|
|||||||
const { width = 0, height = 0 } = useWindowSize();
|
const { width = 0, height = 0 } = useWindowSize();
|
||||||
|
|
||||||
const keysRef = useHotkeys<HTMLDivElement>(
|
const keysRef = useHotkeys<HTMLDivElement>(
|
||||||
[Hotkey.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build, Hotkey.SearchNode],
|
[Hotkey.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build, Hotkey.SearchNode, Hotkey.JumpNode],
|
||||||
(event) => {
|
(event) => {
|
||||||
if (isHotkeyPressed(Hotkey.Save)) {
|
if (isHotkeyPressed(Hotkey.Save)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -67,6 +67,9 @@ export const Workspace: FC = () => {
|
|||||||
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
|
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
workspace.editing?.dispatch("searchNode");
|
workspace.editing?.dispatch("searchNode");
|
||||||
|
} else if (isHotkeyPressed(Hotkey.JumpNode)) {
|
||||||
|
event.preventDefault()
|
||||||
|
workspace.editing?.dispatch("jumpNode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -338,6 +341,7 @@ export const Workspace: FC = () => {
|
|||||||
{ label: t("searchFile"), hotkeys: isMacos ? "⌘ P" : "Ctrl + P" },
|
{ label: t("searchFile"), hotkeys: isMacos ? "⌘ P" : "Ctrl + P" },
|
||||||
{ label: t("build"), hotkeys: isMacos ? "⌘ B" : "Ctrl + B" },
|
{ label: t("build"), hotkeys: isMacos ? "⌘ B" : "Ctrl + B" },
|
||||||
{ label: t("searchNode"), hotkeys: isMacos ? "⌘ F" : "Ctrl + F" },
|
{ label: t("searchNode"), hotkeys: isMacos ? "⌘ F" : "Ctrl + F" },
|
||||||
|
{ label: t("jumpNode"), hotkeys: isMacos ? "⌘ G" : "Ctrl + G" },
|
||||||
{ label: t("insertNode"), hotkeys: "Enter" },
|
{ label: t("insertNode"), hotkeys: "Enter" },
|
||||||
{ label: t("deleteNode"), hotkeys: "Backspace" },
|
{ label: t("deleteNode"), hotkeys: "Backspace" },
|
||||||
].map((v) => (
|
].map((v) => (
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ let buildDir: string | undefined;
|
|||||||
|
|
||||||
interface BatchScript {
|
interface BatchScript {
|
||||||
processTree?(tree: TreeModel): TreeModel;
|
processTree?(tree: TreeModel): TreeModel;
|
||||||
|
|
||||||
processNode?(node: NodeModel, tree: TreeModel): NodeModel;
|
processNode?(node: NodeModel, tree: TreeModel): NodeModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ export type EditEvent =
|
|||||||
| "replace"
|
| "replace"
|
||||||
| "delete"
|
| "delete"
|
||||||
| "insert"
|
| "insert"
|
||||||
|
| "jumpNode"
|
||||||
| "undo"
|
| "undo"
|
||||||
| "redo"
|
| "redo"
|
||||||
| "reload"
|
| "reload"
|
||||||
@@ -387,7 +389,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
saveFile(workspace.editing);
|
saveFile(workspace.editing);
|
||||||
},
|
},
|
||||||
|
|
||||||
saveAs: () => {},
|
saveAs: () => {
|
||||||
|
},
|
||||||
|
|
||||||
saveAll: () => {
|
saveAll: () => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
|
|||||||
+2
-1
@@ -33,7 +33,7 @@ export function useHotkeys<T extends HTMLElement>(
|
|||||||
keys: Keys,
|
keys: Keys,
|
||||||
callback: HotkeyCallback,
|
callback: HotkeyCallback,
|
||||||
options?: OptionsOrDependencyArray,
|
options?: OptionsOrDependencyArray,
|
||||||
dependencies?: OptionsOrDependencyArray
|
dependencies?: OptionsOrDependencyArray,
|
||||||
): MutableRefObject<RefType<T>> {
|
): MutableRefObject<RefType<T>> {
|
||||||
if (keys instanceof Array) {
|
if (keys instanceof Array) {
|
||||||
keys = keys.filter((v) => !!v);
|
keys = keys.filter((v) => !!v);
|
||||||
@@ -52,6 +52,7 @@ export const Hotkey = {
|
|||||||
Escape: Key.Escape,
|
Escape: Key.Escape,
|
||||||
F2: Key.F2,
|
F2: Key.F2,
|
||||||
Insert: Key.Insert,
|
Insert: Key.Insert,
|
||||||
|
JumpNode: hotkey("ctrl+g"),
|
||||||
MacDelete: isMacos ? hotkey("ctrl+backspace") : "",
|
MacDelete: isMacos ? hotkey("ctrl+backspace") : "",
|
||||||
Paste: hotkey("ctrl+v"),
|
Paste: hotkey("ctrl+v"),
|
||||||
Redo: isMacos ? hotkey("shift+ctrl+z") : hotkey("ctrl+y"),
|
Redo: isMacos ? hotkey("shift+ctrl+z") : hotkey("ctrl+y"),
|
||||||
|
|||||||
Reference in new issue
Block a user