Skip to content

Commit 9beffdf

Browse files
committed
feat: ctrl+s保存时自动清空历史记录
1 parent 2581211 commit 9beffdf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/src/core/service/controlService/shortcutKeysEngine/shortcutKeysRegister.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ export class KeyBindsRegistrar {
376376
// }, 200);
377377
// });
378378
await this.project.keyBinds.create("saveFile", "C-s", () => {
379-
store.get(activeProjectAtom)?.save();
379+
const activeProject = store.get(activeProjectAtom);
380+
if (activeProject) {
381+
activeProject.save();
382+
activeProject.historyManager.clearHistory();
383+
}
380384
});
381385
await this.project.keyBinds.create("newDraft", "C-n", () => {
382386
onNewDraft();

app/src/core/stage/stageManager/StageHistoryManager.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,16 @@ export class HistoryManager {
180180
const stage = deserialize(data, this.project);
181181
return stage;
182182
}
183+
184+
/**
185+
* 清空历史记录
186+
* 保存文件时调用,将当前状态设为新的初始状态
187+
*/
188+
clearHistory() {
189+
this.deltas = [];
190+
this.currentIndex = -1;
191+
this.initialStage = serialize(this.project.stage);
192+
this.project.state = ProjectState.Saved;
193+
toast("历史记录已清空");
194+
}
183195
}

0 commit comments

Comments
 (0)