Vanessa 2025-12-22 10:54:35 +08:00
parent 2d1618e639
commit 419683fe5a
3 changed files with 29 additions and 7 deletions

View file

@ -68,11 +68,31 @@ export class Undo {
hideElements(["hint", "gutter"], protyle);
protyle.wysiwyg.lastHTMLs = {};
if (!redo) {
state.undoOperations.forEach(item => {
for (let i = state.undoOperations.length - 1; i >= 0; i--) {
if (state.undoOperations[i].action === "insert") {
if (state.undoOperations[i].context) {
state.undoOperations[i].context.setRange = "true";
} else {
state.undoOperations[i].context = {setRange: "true"};
}
break;
}
}
state.undoOperations.forEach((item) => {
onTransaction(protyle, item, true);
});
transaction(protyle, state.undoOperations);
} else {
for (let i = state.doOperations.length - 1; i >= 0; i--) {
if (state.doOperations[i].action === "insert") {
if (state.doOperations[i].context) {
state.doOperations[i].context.setRange = "true";
} else {
state.doOperations[i].context = {setRange: "true"};
}
break;
}
}
state.doOperations.forEach(item => {
onTransaction(protyle, item, true);
});

View file

@ -874,11 +874,13 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
blockRender(protyle, item);
const wbrElement = item.querySelector("wbr");
if (isUndo) {
const range = getEditorRange(item);
if (wbrElement) {
focusByWbr(item, range);
} else {
focusBlock(item);
if (operation.context?.setRange === "true") {
const range = getEditorRange(item);
if (wbrElement) {
focusByWbr(item, range);
} else {
focusBlock(item);
}
}
} else if (wbrElement) {
wbrElement.remove();

View file

@ -552,7 +552,7 @@ interface ISiyuan {
interface IOperation {
action: TOperation, // move delete 不需要传 data
id?: string,
context?: IObject,
context?: IObject, // focusId, message, ignoreProcess, setRange
blockID?: string,
isTwoWay?: boolean, // 是否双向关联
backRelationKeyID?: string, // 双向关联的目标关联列 ID