trigger search node in workspace

This commit is contained in:
codetypes committed 2024-04-26 10:06:57 +08:00
1 parent 82d1d89311
commit 21df9b7cca
6 files changed
+23 -21

No files matched your search

+5 -6
View File
@@ -790,7 +790,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
Hotkey.Delete, Hotkey.Delete,
Hotkey.Enter, Hotkey.Enter,
Hotkey.Backspace, Hotkey.Backspace,
Hotkey.SearchNode,
], ],
(event) => { (event) => {
event.preventDefault(); event.preventDefault();
@@ -808,13 +807,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
createNode(); createNode();
} else if (isHotkeyPressed(Hotkey.Delete) || isHotkeyPressed(Hotkey.Backspace)) { } else if (isHotkeyPressed(Hotkey.Delete) || isHotkeyPressed(Hotkey.Backspace)) {
deleteNode(); deleteNode();
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
setShowingSearch(true);
} }
} }
); );
if (!editor.dispatch) {
editor.dispatch = (event: EditEvent, data: unknown) => { editor.dispatch = (event: EditEvent, data: unknown) => {
switch (event) { switch (event) {
case "copy": { case "copy": {
@@ -865,6 +861,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
updateNode(data as EditNode); updateNode(data as EditNode);
break; break;
} }
case "searchNode": {
setShowingSearch(true);
break;
}
case "editSubtree": { case "editSubtree": {
editSubtree(); editSubtree();
break; break;
@@ -875,7 +875,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
} }
}; };
}
useEffect(() => { useEffect(() => {
if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) { if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) {
@@ -988,7 +987,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
type MenuInfo = Parameters<Exclude<MenuProps["onClick"], undefined>>[0]; type MenuInfo = Parameters<Exclude<MenuProps["onClick"], undefined>>[0];
const onClick = useCallback((info: MenuInfo) => { const onClick = useCallback((info: MenuInfo) => {
editor.dispatch?.(info.key as EditEvent); editor.dispatch(info.key as EditEvent);
}, []); }, []);
return ( return (
+4 -4
View File
@@ -99,11 +99,11 @@ const renameFile = (oldPath: string, newPath: string) => {
for (const editor of workspace.editors) { for (const editor of workspace.editors) {
if (isDirectory) { if (isDirectory) {
if (editor.path.startsWith(oldPath)) { if (editor.path.startsWith(oldPath)) {
editor.dispatch?.("rename", editor.path.replace(oldPath, newPath)); editor.dispatch("rename", editor.path.replace(oldPath, newPath));
} }
} else { } else {
if (editor.path === oldPath) { if (editor.path === oldPath) {
editor.dispatch?.("rename", newPath); editor.dispatch("rename", newPath);
} }
} }
} }
@@ -496,12 +496,12 @@ export const Explorer: FC = () => {
fs.renameSync(node.path, newPath); fs.renameSync(node.path, newPath);
for (const editor of workspace.editors) { for (const editor of workspace.editors) {
if (editor.path.startsWith(node.path)) { if (editor.path.startsWith(node.path)) {
editor.dispatch?.("rename", dest!.path + "/" + Path.basename(editor.path)); editor.dispatch("rename", dest!.path + "/" + Path.basename(editor.path));
} }
console.log("editor move", editor.path === newPath, editor.path, newPath); console.log("editor move", editor.path === newPath, editor.path, newPath);
if (editor.path.startsWith(newPath)) { if (editor.path.startsWith(newPath)) {
console.log("editor reload", editor.path === newPath, editor.path, newPath); console.log("editor reload", editor.path === newPath, editor.path, newPath);
editor.dispatch?.("reload"); editor.dispatch("reload");
} }
} }
}; };
+2 -2
View File
@@ -30,7 +30,7 @@ const TreeInspector: FC = () => {
const data = {} as TreeModel; const data = {} as TreeModel;
data.name = values.name; data.name = values.name;
data.desc = values.desc || undefined; data.desc = values.desc || undefined;
workspace.editing?.dispatch?.("updateTree", { workspace.editing?.dispatch("updateTree", {
data: { data: {
name: values.name, name: values.name,
desc: values.desc || undefined, desc: values.desc || undefined,
@@ -174,7 +174,7 @@ const NodeInspector: FC = () => {
data.output ||= []; data.output ||= [];
data.output.push(v ?? ""); data.output.push(v ?? "");
}); });
workspace.editing?.dispatch?.("updateNode", { workspace.editing?.dispatch("updateNode", {
data: data, data: data,
} as EditNode); } as EditNode);
}; };
+2 -2
View File
@@ -221,7 +221,7 @@ export const Menu: FC<LayoutProps> = () => {
label: t("insertNode"), label: t("insertNode"),
enabled: enabled, enabled: enabled,
click: () => { click: () => {
workspace.editing?.dispatch?.("insert"); workspace.editing?.dispatch("insert");
}, },
}, },
{ {
@@ -229,7 +229,7 @@ export const Menu: FC<LayoutProps> = () => {
label: t("deleteNode"), label: t("deleteNode"),
enabled: enabled, enabled: enabled,
click: () => { click: () => {
workspace.editing?.dispatch?.("delete"); workspace.editing?.dispatch("delete");
}, },
}, },
], ],
+6 -3
View File
@@ -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.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build, Hotkey.SearchNode],
(event) => { (event) => {
if (isHotkeyPressed(Hotkey.Save)) { if (isHotkeyPressed(Hotkey.Save)) {
event.preventDefault(); event.preventDefault();
@@ -64,6 +64,9 @@ export const Workspace: FC = () => {
} else if (isHotkeyPressed(Hotkey.Build)) { } else if (isHotkeyPressed(Hotkey.Build)) {
event.preventDefault(); event.preventDefault();
workspace.buildProject(); workspace.buildProject();
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
event.preventDefault();
workspace.editing?.dispatch("searchNode");
} }
} }
); );
@@ -95,7 +98,7 @@ export const Workspace: FC = () => {
<Button <Button
type="primary" type="primary"
onClick={() => { onClick={() => {
editor.dispatch?.("save"); editor.dispatch("save");
workspace.close(editor.path); workspace.close(editor.path);
alert.destroy(); alert.destroy();
keysRef.current?.focus(); keysRef.current?.focus();
@@ -163,7 +166,7 @@ export const Workspace: FC = () => {
<Button <Button
type="primary" type="primary"
onClick={() => { onClick={() => {
unsaves.forEach((editor) => editor.dispatch?.("save")); unsaves.forEach((editor) => editor.dispatch("save"));
alert.destroy(); alert.destroy();
window.close(); window.close();
setShowingSave(false); setShowingSave(false);
+4 -4
View File
@@ -54,7 +54,7 @@ export class EditorStore {
graphMatrix?: Matrix; graphMatrix?: Matrix;
graph!: TreeGraph; graph!: TreeGraph;
dispatch?: (event: EditEvent, data?: unknown) => void; dispatch!: (event: EditEvent, data?: unknown) => void;
constructor(path: string) { constructor(path: string) {
this.path = path; this.path = path;
@@ -182,7 +182,7 @@ const loadFileTree = (workdir: string, filename: string) => {
const saveFile = (editor?: EditorStore) => { const saveFile = (editor?: EditorStore) => {
if (editor?.unsave) { if (editor?.unsave) {
editor.dispatch?.("save"); editor.dispatch("save");
} }
}; };
@@ -251,7 +251,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
} }
if (buildDir) { if (buildDir) {
for (const editor of workspace.editors) { for (const editor of workspace.editors) {
editor.dispatch?.("save"); editor.dispatch("save");
} }
try { try {
let hasError = false; let hasError = false;
@@ -448,7 +448,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
nodeDefs.set(v.name, v); nodeDefs.set(v.name, v);
} }
set({ nodeDefs }); set({ nodeDefs });
workspace.editing?.dispatch?.("reload"); workspace.editing?.dispatch("reload");
}, },
// node edit // node edit