Skip to content

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

:bug: Keep nested super block text selections at child level https://github.com/siyuan-note/siyuan/issues/19000

Danielf9b33aa46986
diff --git a/app/src/protyle/util/blockRangeSelect.test.ts b/app/src/protyle/util/blockRangeSelect.test.ts
index 835413c329..3ac51ac9be 100644
--- a/app/src/protyle/util/blockRangeSelect.test.ts
+++ b/app/src/protyle/util/blockRangeSelect.test.ts
@@ -111,4 +111,28 @@ describe("getBlockRangeSelectElements", () => {
assert.deepEqual(getBlockRangeSelectElements(asElement(first), asElement(second), getBlock).selectElements,
[asElement(first), asElement(second)]);
});
+
+ it("keeps child blocks selected in the left vertical super block", () => {
+ const editor = new TestElement("editor", 0, ["protyle-wysiwyg"]);
+ const outer = block("outer", 0, "NodeSuperBlock", ["sb"]);
+ const left = block("left", 0, "NodeSuperBlock", ["sb"]);
+ const first = block("first", 10);
+ const second = block("second", 20);
+ const leftAttr = new TestElement("left-attr", 20, ["protyle-attr"]);
+ const resize = new TestElement("resize", 0, ["sb__resize"]);
+ const right = block("right", 0, "NodeSuperBlock", ["sb"]);
+ const third = block("third", 10);
+ const fourth = block("fourth", 20);
+ const rightAttr = new TestElement("right-attr", 20, ["protyle-attr"]);
+ const outerAttr = new TestElement("outer-attr", 20, ["protyle-attr"]);
+ editor.append(outer.append(left.append(first, second, leftAttr), resize,
+ right.append(third, fourth, rightAttr), outerAttr));
+
+ const expected = [asElement(first), asElement(second)];
+ assert.deepEqual(getBlockRangeSelectElements(asElement(first), asElement(second), getBlock).selectElements,
+ expected);
+ const upwardSelection = getBlockRangeSelectElements(asElement(second), asElement(first), getBlock);
+ assert.deepEqual(upwardSelection.selectElements, expected);
+ assert.equal(upwardSelection.toDown, false);
+ });
});
diff --git a/app/src/protyle/util/blockRangeSelect.ts b/app/src/protyle/util/blockRangeSelect.ts
index b7be709547..da9f1e82d2 100644
--- a/app/src/protyle/util/blockRangeSelect.ts
+++ b/app/src/protyle/util/blockRangeSelect.ts
@@ -58,6 +58,10 @@ export const getBlockRangeSelectElements = (rangeStartElement: HTMLElement, rang
if (!currentElement.classList.contains("sb__resize")) {
selectElements.push(currentElement);
}
+ // 到达实际选区终点后停止,避免经过属性节点继续提升到父容器。
+ if (currentElement === endElement) {
+ break;
+ }
const parentElement = currentElement.parentElement;
currentElement = currentElement.nextElementSibling as HTMLElement;
// 提示块内容使用无块 ID 的包装层,末尾需回到提示块后继续遍历同级块。