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
+44 -15

No files matched your search

+5 -2
View File
@@ -3,7 +3,9 @@
"desc": "", "desc": "",
"firstid": 1, "firstid": 1,
"export": true, "export": true,
"import": ["vars/declare-core.json"], "import": [
"vars/declare-core.json"
],
"declvar": [ "declvar": [
{ {
"name": "owner", "name": "owner",
@@ -17,5 +19,6 @@
"root": { "root": {
"id": 1, "id": 1,
"name": "Sequence" "name": "Sequence"
} },
"group": []
} }
-4
View File
@@ -18,10 +18,6 @@
{ {
"name": "target1", "name": "target1",
"desc": "其它目标" "desc": "其它目标"
},
{
"name": "test",
"desc": "测试"
} }
], ],
"root": { "root": {
+27 -7
View File
@@ -218,6 +218,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
relative: state.relative, relative: state.relative,
updateFileMeta: state.updateFileMeta, updateFileMeta: state.updateFileMeta,
nodeDefs: state.nodeDefs, 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)); .sort((a, b) => a.name.localeCompare(b.name));
b3util.updateUsingGroups(editor.data.group); b3util.updateUsingGroups(editor.data.group);
b3util.updateUsingVars(collectVarDefs(editor)); b3util.updateUsingVars(collectVarDefs(editor));
pushHistory();
refresh(); refresh();
onChange(); onChange();
} }
@@ -584,7 +587,16 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
const pushHistory = () => { const pushHistory = () => {
editor.historyStack.length = ++editor.historyIndex; 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 = () => { const copyNode = () => {
@@ -728,13 +740,23 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
editor.graph.findById(data.id)?.draw(); editor.graph.findById(data.id)?.draw();
}; };
const useStackData = (data: NodeModel) => { const useStackData = (str: string) => {
editor.root = createTreeData(data); 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.autoId = b3util.refreshTreeDataId(editor.root, editor.data.firstid);
editor.graph.changeData(editor.root); editor.graph.changeData(editor.root);
editor.graph.layout(); editor.graph.layout();
restoreViewport(); restoreViewport();
onChange(); onChange();
if (workspace.editingTree) {
workspace.onEditingTree(editor);
} else if (workspace.editingNode) {
selectNode(workspace.editingNode.data.id.toString());
}
}; };
const updateGrahp = () => { const updateGrahp = () => {
@@ -744,16 +766,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
const undo = () => { const undo = () => {
if (editor.historyIndex > 0) { if (editor.historyIndex > 0) {
const data = editor.historyStack[--editor.historyIndex]; useStackData(editor.historyStack[--editor.historyIndex]);
useStackData(data);
updateSearchState(); updateSearchState();
} }
}; };
const redo = () => { const redo = () => {
if (editor.historyIndex < editor.historyStack.length - 1) { if (editor.historyIndex < editor.historyStack.length - 1) {
const data = editor.historyStack[++editor.historyIndex]; useStackData(editor.historyStack[++editor.historyIndex]);
useStackData(data);
updateSearchState(); updateSearchState();
} }
}; };
+11 -2
View File
@@ -58,7 +58,7 @@ export class EditorStore {
alertReload: boolean = false; alertReload: boolean = false;
searchingText?: string; searchingText?: string;
historyStack: NodeModel[] = []; historyStack: string[] = [];
historyIndex: number = 0; historyIndex: number = 0;
selectedId?: string | null; selectedId?: string | null;
@@ -79,7 +79,16 @@ export class EditorStore {
this.import = this.data.import.map((v) => ({ path: v, vars: [] })); this.import = this.data.import.map((v) => ({ path: v, vars: [] }));
this.declvar = this.data.declvar.map((v) => ({ ...v })); this.declvar = this.data.declvar.map((v) => ({ ...v }));
this.autoId = b3util.refreshTreeDataId(this.root, this.data.firstid); 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; this.historyIndex = 0;
} }
} }
+1
View File
@@ -721,6 +721,7 @@ export const loadVarDef = (list: ImportDef[]) => {
// TODO: check file date // TODO: check file date
// TODO: use cache // TODO: use cache
if (entry.vars.length) { if (entry.vars.length) {
entry.vars.forEach((v) => all.add(v));
continue; continue;
} }
const filter: Map<string, boolean> = new Map(); const filter: Map<string, boolean> = new Map();