Vanessa 2023-06-01 14:56:21 +08:00
parent 8c35440a77
commit 74b4a00a2f
42 changed files with 426 additions and 270 deletions

View file

@ -7,6 +7,7 @@ import {scrollCenter} from "../../util/highlightById";
import {getCurrentWindow} from "@electron/remote";
/// #endif
import {matchHotKey} from "../util/hotKey";
import {App} from "../../index";
interface IOperations {
doOperations: IOperation[],
@ -23,7 +24,7 @@ export class Undo {
this.undoStack = [];
}
public undo(protyle: IProtyle) {
public undo(app: App, protyle: IProtyle) {
if (protyle.disabled) {
return;
}
@ -31,13 +32,13 @@ export class Undo {
return;
}
const state = this.undoStack.pop();
this.render(protyle, state, false);
this.render(app, protyle, state, false);
this.hasUndo = true;
this.redoStack.push(state);
}
public redo(protyle: IProtyle) {
public redo(app: App, protyle: IProtyle) {
if (protyle.disabled) {
return;
}
@ -45,21 +46,21 @@ export class Undo {
return;
}
const state = this.redoStack.pop();
this.render(protyle, state, true);
this.render(app, protyle, state, true);
this.undoStack.push(state);
}
private render(protyle: IProtyle, state: IOperations, redo: boolean) {
private render(app: App, protyle: IProtyle, state: IOperations, redo: boolean) {
hideElements(["hint", "gutter"], protyle);
protyle.wysiwyg.lastHTMLs = {};
if (!redo) {
state.undoOperations.forEach(item => {
onTransaction(protyle, item, true);
onTransaction(app, protyle, item, true);
});
transaction(protyle, state.undoOperations);
} else {
state.doOperations.forEach(item => {
onTransaction(protyle, item, true);
onTransaction(app, protyle, item, true);
});
transaction(protyle, state.doOperations);
}