Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/16644

Vanessa419683fe5af7
diff --git a/app/src/protyle/undo/index.ts b/app/src/protyle/undo/index.ts
index c2ab932170..21f5416987 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 1531e34dc1..fc85b3e286 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 da3717df5f..1cfa54c618 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