Skip to content

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

:bug: Preserve editable callout title during inline cleanup https://github.com/siyuan-note/siyuan/issues/19077

Daniel4251bab2944a
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 8a771a35ec..8411d4f256 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -92,6 +92,7 @@ import {
} from "../util/inlineElementMarker";
import {
canExpandInlineRangeToParent,
+ canRemoveEmptyInlineElement,
getInlineRangeElement,
normalizeCalloutTitleRange
} from "./inlineRangeBoundary";
@@ -904,7 +905,7 @@ export class Toolbar {
if (emptyNode && emptyNode.nodeType !== 3 &&
(hasSemanticInlineType(emptyNode.getAttribute("data-type")) ?
getSemanticInlineVisibleText(emptyNode) : emptyNode.textContent.replace(Constants.ZWSP, "")) === "" &&
- !["TD", "TH", "BR"].includes(emptyNode.tagName)) {
+ canRemoveEmptyInlineElement(emptyNode, editableElement)) {
emptyNode.remove();
}
}
diff --git a/app/src/protyle/toolbar/inlineRangeBoundary.test.ts b/app/src/protyle/toolbar/inlineRangeBoundary.test.ts
index ad36d2adb4..e86e74cdd1 100644
--- a/app/src/protyle/toolbar/inlineRangeBoundary.test.ts
+++ b/app/src/protyle/toolbar/inlineRangeBoundary.test.ts
@@ -2,6 +2,7 @@ import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
import {
canExpandInlineRangeToParent,
+ canRemoveEmptyInlineElement,
getInlineRangeElement,
normalizeCalloutTitleRange
} from "./inlineRangeBoundary";
@@ -22,6 +23,7 @@ describe("inline range boundary", () => {
assert.equal(getInlineRangeElement(text(calloutTitle), calloutTitle), undefined);
assert.equal(canExpandInlineRangeToParent(text(calloutTitle), calloutTitle), false);
+ assert.equal(canRemoveEmptyInlineElement(calloutTitle, calloutTitle), false);
});
it("recognizes inline elements nested inside an editable root", () => {
@@ -31,6 +33,7 @@ describe("inline range boundary", () => {
assert.equal(getInlineRangeElement(textNode, calloutTitle), inlineElement);
assert.equal(canExpandInlineRangeToParent(textNode, calloutTitle), true);
+ assert.equal(canRemoveEmptyInlineElement(inlineElement, calloutTitle), true);
});
it("keeps existing block-level editable boundaries", () => {
diff --git a/app/src/protyle/toolbar/inlineRangeBoundary.ts b/app/src/protyle/toolbar/inlineRangeBoundary.ts
index 86442f958e..e8f27d0a86 100644
--- a/app/src/protyle/toolbar/inlineRangeBoundary.ts
+++ b/app/src/protyle/toolbar/inlineRangeBoundary.ts
@@ -14,6 +14,9 @@ export const canExpandInlineRangeToParent = (container: Node, editableElement: E
return !!parentElement && parentElement !== editableElement && !INLINE_RANGE_ROOT_TAGS.includes(parentElement.tagName);
};
+export const canRemoveEmptyInlineElement = (element: Element, editableElement: Element) =>
+ element !== editableElement && !["TD", "TH", "BR"].includes(element.tagName);
+
export const normalizeCalloutTitleRange = (range: Range, blockElement: Element,
editableElement: Element) => {
if (blockElement.getAttribute("data-type") !== "NodeCallout") {