undo & redo for file info

This commit is contained in:
codetypes committed 2025-03-18 22:53:31 +08:00
1 parent 4d1d09fe80
commit d9dbf15d30
5 files changed
+45 -16

No files matched your search

+27 -7
View File
@@ -218,6 +218,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
relative: state.relative,
updateFileMeta: state.updateFileMeta,
nodeDefs: state.nodeDefs,
editingTree: state.editingTree,
editingNode: state.editingNode,
}))
);
@@ -550,6 +552,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
.sort((a, b) => a.name.localeCompare(b.name));
b3util.updateUsingGroups(editor.data.group);
b3util.updateUsingVars(collectVarDefs(editor));
pushHistory();
refresh();
onChange();
}
@@ -584,7 +587,16 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
const pushHistory = () => {
editor.historyStack.length = ++editor.historyIndex;
editor.historyStack.push(b3util.createNode(editor.root));
editor.historyStack.push(
JSON.stringify(
{
...editor.data,
root: b3util.createNode(editor.root),
},
null,
2
)
);
};
const copyNode = () => {
@@ -728,13 +740,23 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
editor.graph.findById(data.id)?.draw();
};
const useStackData = (data: NodeModel) => {
editor.root = createTreeData(data);
const useStackData = (str: string) => {
const data = JSON.parse(str) as TreeModel;
editor.data = data;
editor.root = createTreeData(data.root);
editor.import = data.import.map((v) => ({ path: v, vars: [] }));
editor.declvar = data.declvar.map((v) => ({ ...v }));
editor.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
editor.graph.changeData(editor.root);
editor.graph.layout();
restoreViewport();
onChange();
if (workspace.editingTree) {
workspace.onEditingTree(editor);
} else if (workspace.editingNode) {
selectNode(workspace.editingNode.data.id.toString());
}
};
const updateGrahp = () => {
@@ -744,16 +766,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
const undo = () => {
if (editor.historyIndex > 0) {
const data = editor.historyStack[--editor.historyIndex];
useStackData(data);
useStackData(editor.historyStack[--editor.historyIndex]);
updateSearchState();
}
};
const redo = () => {
if (editor.historyIndex < editor.historyStack.length - 1) {
const data = editor.historyStack[++editor.historyIndex];
useStackData(data);
useStackData(editor.historyStack[++editor.historyIndex]);
updateSearchState();
}
};
+11 -2
View File
@@ -58,7 +58,7 @@ export class EditorStore {
alertReload: boolean = false;
searchingText?: string;
historyStack: NodeModel[] = [];
historyStack: string[] = [];
historyIndex: number = 0;
selectedId?: string | null;
@@ -79,7 +79,16 @@ export class EditorStore {
this.import = this.data.import.map((v) => ({ path: v, vars: [] }));
this.declvar = this.data.declvar.map((v) => ({ ...v }));
this.autoId = b3util.refreshTreeDataId(this.root, this.data.firstid);
this.historyStack.push(b3util.createNode(this.root));
this.historyStack.push(
JSON.stringify(
{
...this.data,
root: b3util.createNode(this.root),
},
null,
2
)
);
this.historyIndex = 0;
}
}
+1
View File
@@ -721,6 +721,7 @@ export const loadVarDef = (list: ImportDef[]) => {
// TODO: check file date
// TODO: use cache
if (entry.vars.length) {
entry.vars.forEach((v) => all.add(v));
continue;
}
const filter: Map<string, boolean> = new Map();