Skip to content

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

:bug: Prevent Lite editor reload after undo https://github.com/siyuan-note/siyuan/issues/19137

Daniel3a36427c120d
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index 8a72481434..6930b4d350 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -46,7 +46,11 @@ import {
queueHeadingNumberRefresh
} from "../util/headingNumber";
import {MERMAID_LAYOUT_ATTR} from "../render/mermaidLayout";
-import {getPartialUpdateCleanupElements, shouldDeferCodeBlockCaretRestore} from "./transactionUpdate";
+import {
+ getPartialUpdateCleanupElements,
+ shouldDeferCodeBlockCaretRestore,
+ shouldReloadForHeadingBatch,
+} from "./transactionUpdate";
import {getMoveAffectedEmbedElements, shouldSyncMoveCopies} from "./transactionEmbed";
import {cloneMoveElements, getVisibleMoveElements} from "./transactionMove";
import {normalizeHTMLAssetIFrameBlockDOM} from "../../asset/html";
@@ -1405,7 +1409,7 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd
});
});
queueHeadingNumberRefresh(protyle, operations);
- if (operations.some(operation => operation.context?.headingBatchRootID === protyle.block.rootID)) {
+ if (shouldReloadForHeadingBatch(protyle.block.rootID, operations)) {
reloadProtyle(protyle, false);
}
};
diff --git a/app/src/protyle/wysiwyg/transactionUpdate.test.ts b/app/src/protyle/wysiwyg/transactionUpdate.test.ts
index 4692f0e6d9..063c735c56 100644
--- a/app/src/protyle/wysiwyg/transactionUpdate.test.ts
+++ b/app/src/protyle/wysiwyg/transactionUpdate.test.ts
@@ -1,6 +1,10 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {getPartialUpdateCleanupElements, shouldDeferCodeBlockCaretRestore} from "./transactionUpdate";
+import {
+ getPartialUpdateCleanupElements,
+ shouldDeferCodeBlockCaretRestore,
+ shouldReloadForHeadingBatch,
+} from "./transactionUpdate";
describe("getPartialUpdateCleanupElements", () => {
const breadcrumb = {id: "breadcrumb"};
@@ -46,3 +50,21 @@ describe("shouldDeferCodeBlockCaretRestore", () => {
assert.equal(shouldDeferCodeBlockCaretRestore({...replayCodeBlock, isCodeBlock: false}), false);
});
});
+
+describe("shouldReloadForHeadingBatch", () => {
+ it("does not reload when both the Lite root and the operation context omit a root ID", () => {
+ assert.equal(shouldReloadForHeadingBatch(undefined, [{}]), false);
+ });
+
+ it("reloads when an operation targets the current heading batch root", () => {
+ assert.equal(shouldReloadForHeadingBatch("root", [{
+ context: {headingBatchRootID: "root"},
+ }]), true);
+ });
+
+ it("does not reload for another heading batch root", () => {
+ assert.equal(shouldReloadForHeadingBatch("root", [{
+ context: {headingBatchRootID: "other"},
+ }]), false);
+ });
+});
diff --git a/app/src/protyle/wysiwyg/transactionUpdate.ts b/app/src/protyle/wysiwyg/transactionUpdate.ts
index e2edb37541..ab258e862a 100644
--- a/app/src/protyle/wysiwyg/transactionUpdate.ts
+++ b/app/src/protyle/wysiwyg/transactionUpdate.ts
@@ -16,3 +16,11 @@ export const shouldDeferCodeBlockCaretRestore = (options: {
isCodeBlock: boolean,
isRendered: boolean,
}) => options.isRangeBlock && options.isReplay && options.hasCaret && options.isCodeBlock && !options.isRendered;
+
+export const shouldReloadForHeadingBatch = (
+ rootID: string | undefined,
+ operations: Array<{context?: {headingBatchRootID?: string}}>,
+) => operations.some(operation => {
+ const headingBatchRootID = operation.context?.headingBatchRootID;
+ return Boolean(headingBatchRootID) && headingBatchRootID === rootID;
+});