trigger search node in workspace
This commit is contained in:
1 parent
82d1d89311
commit
21df9b7cca
6 files changed
+23
-21
No files matched your search
@@ -790,7 +790,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
Hotkey.Delete,
|
||||
Hotkey.Enter,
|
||||
Hotkey.Backspace,
|
||||
Hotkey.SearchNode,
|
||||
],
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
@@ -808,13 +807,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
createNode();
|
||||
} else if (isHotkeyPressed(Hotkey.Delete) || isHotkeyPressed(Hotkey.Backspace)) {
|
||||
deleteNode();
|
||||
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
|
||||
setShowingSearch(true);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!editor.dispatch) {
|
||||
editor.dispatch = (event: EditEvent, data: unknown) => {
|
||||
switch (event) {
|
||||
case "copy": {
|
||||
@@ -865,6 +861,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
updateNode(data as EditNode);
|
||||
break;
|
||||
}
|
||||
case "searchNode": {
|
||||
setShowingSearch(true);
|
||||
break;
|
||||
}
|
||||
case "editSubtree": {
|
||||
editSubtree();
|
||||
break;
|
||||
@@ -875,7 +875,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
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];
|
||||
const onClick = useCallback((info: MenuInfo) => {
|
||||
editor.dispatch?.(info.key as EditEvent);
|
||||
editor.dispatch(info.key as EditEvent);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
@@ -99,11 +99,11 @@ const renameFile = (oldPath: string, newPath: string) => {
|
||||
for (const editor of workspace.editors) {
|
||||
if (isDirectory) {
|
||||
if (editor.path.startsWith(oldPath)) {
|
||||
editor.dispatch?.("rename", editor.path.replace(oldPath, newPath));
|
||||
editor.dispatch("rename", editor.path.replace(oldPath, newPath));
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
for (const editor of workspace.editors) {
|
||||
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);
|
||||
if (editor.path.startsWith(newPath)) {
|
||||
console.log("editor reload", editor.path === newPath, editor.path, newPath);
|
||||
editor.dispatch?.("reload");
|
||||
editor.dispatch("reload");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ const TreeInspector: FC = () => {
|
||||
const data = {} as TreeModel;
|
||||
data.name = values.name;
|
||||
data.desc = values.desc || undefined;
|
||||
workspace.editing?.dispatch?.("updateTree", {
|
||||
workspace.editing?.dispatch("updateTree", {
|
||||
data: {
|
||||
name: values.name,
|
||||
desc: values.desc || undefined,
|
||||
@@ -174,7 +174,7 @@ const NodeInspector: FC = () => {
|
||||
data.output ||= [];
|
||||
data.output.push(v ?? "");
|
||||
});
|
||||
workspace.editing?.dispatch?.("updateNode", {
|
||||
workspace.editing?.dispatch("updateNode", {
|
||||
data: data,
|
||||
} as EditNode);
|
||||
};
|
||||
|
||||
@@ -221,7 +221,7 @@ export const Menu: FC<LayoutProps> = () => {
|
||||
label: t("insertNode"),
|
||||
enabled: enabled,
|
||||
click: () => {
|
||||
workspace.editing?.dispatch?.("insert");
|
||||
workspace.editing?.dispatch("insert");
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -229,7 +229,7 @@ export const Menu: FC<LayoutProps> = () => {
|
||||
label: t("deleteNode"),
|
||||
enabled: enabled,
|
||||
click: () => {
|
||||
workspace.editing?.dispatch?.("delete");
|
||||
workspace.editing?.dispatch("delete");
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -44,7 +44,7 @@ export const Workspace: FC = () => {
|
||||
const { width = 0, height = 0 } = useWindowSize();
|
||||
|
||||
const keysRef = useHotkeys<HTMLDivElement>(
|
||||
[Hotkey.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build],
|
||||
[Hotkey.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build, Hotkey.SearchNode],
|
||||
(event) => {
|
||||
if (isHotkeyPressed(Hotkey.Save)) {
|
||||
event.preventDefault();
|
||||
@@ -64,6 +64,9 @@ export const Workspace: FC = () => {
|
||||
} else if (isHotkeyPressed(Hotkey.Build)) {
|
||||
event.preventDefault();
|
||||
workspace.buildProject();
|
||||
} else if (isHotkeyPressed(Hotkey.SearchNode)) {
|
||||
event.preventDefault();
|
||||
workspace.editing?.dispatch("searchNode");
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -95,7 +98,7 @@ export const Workspace: FC = () => {
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
editor.dispatch?.("save");
|
||||
editor.dispatch("save");
|
||||
workspace.close(editor.path);
|
||||
alert.destroy();
|
||||
keysRef.current?.focus();
|
||||
@@ -163,7 +166,7 @@ export const Workspace: FC = () => {
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
unsaves.forEach((editor) => editor.dispatch?.("save"));
|
||||
unsaves.forEach((editor) => editor.dispatch("save"));
|
||||
alert.destroy();
|
||||
window.close();
|
||||
setShowingSave(false);
|
||||
|
||||
@@ -54,7 +54,7 @@ export class EditorStore {
|
||||
graphMatrix?: Matrix;
|
||||
graph!: TreeGraph;
|
||||
|
||||
dispatch?: (event: EditEvent, data?: unknown) => void;
|
||||
dispatch!: (event: EditEvent, data?: unknown) => void;
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path;
|
||||
@@ -182,7 +182,7 @@ const loadFileTree = (workdir: string, filename: string) => {
|
||||
|
||||
const saveFile = (editor?: EditorStore) => {
|
||||
if (editor?.unsave) {
|
||||
editor.dispatch?.("save");
|
||||
editor.dispatch("save");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -251,7 +251,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
}
|
||||
if (buildDir) {
|
||||
for (const editor of workspace.editors) {
|
||||
editor.dispatch?.("save");
|
||||
editor.dispatch("save");
|
||||
}
|
||||
try {
|
||||
let hasError = false;
|
||||
@@ -448,7 +448,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
nodeDefs.set(v.name, v);
|
||||
}
|
||||
set({ nodeDefs });
|
||||
workspace.editing?.dispatch?.("reload");
|
||||
workspace.editing?.dispatch("reload");
|
||||
},
|
||||
|
||||
// node edit
|
||||
|
||||
Reference in new issue
Block a user