From 419683fe5af78b8b478d618c286229ad47c45991 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 22 Dec 2025 10:54:35 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/16644 --- app/src/protyle/undo/index.ts | 22 +++++++++++++++++++++- app/src/protyle/wysiwyg/transaction.ts | 12 +++++++----- app/src/types/index.d.ts | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/src/protyle/undo/index.ts b/app/src/protyle/undo/index.ts index c2ab93217..21f541698 100644 --- a/app/src/protyle/undo/index.ts +++ b/app/src/protyle/undo/index.ts @@ -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); }); diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 1531e34dc..fc85b3e28 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -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(); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index da3717df5..1cfa54c61 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -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