An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve drag selection for child blocks in list items https://github.com/siyuan-note/siyuan/issues/18901
Daniel330955e853c3
diff --git a/app/src/protyle/wysiwyg/blockDragSelect.test.ts b/app/src/protyle/wysiwyg/blockDragSelect.test.tsindex e3402a892e..7d343c41ce 100644--- a/app/src/protyle/wysiwyg/blockDragSelect.test.ts+++ b/app/src/protyle/wysiwyg/blockDragSelect.test.ts@@ -97,18 +97,51 @@ describe("getBlockDragSelectBlock", () => {const isContainerBlock = (element: Element) => (element as unknown as TestElement).containerSurface;const isListItem = (element: Element) => (element as unknown as TestElement).name === "listItem";- it("selects a list item instead of its content block", () => {+ it("selects a list item instead of its primary content block", () => {const editor = new TestElement("editor");const list = new TestElement("list", true, true);const listItem = new TestElement("listItem", true, true);+ const action = new TestElement("action");const paragraph = new TestElement("paragraph", true);const content = new TestElement("content");- editor.append(list.append(listItem.append(paragraph.append(content))));+ editor.append(list.append(listItem.append(action, paragraph.append(content))));assert.equal(getBlockDragSelectBlock(asElement(content), asElement(editor), getBlock,isContainerBlock, isListItem), asElement(listItem));});+ it("selects an additional list item child block independently", () => {+ const editor = new TestElement("editor");+ const list = new TestElement("list", true, true);+ const listItem = new TestElement("listItem", true, true);+ const action = new TestElement("action");+ const paragraph = new TestElement("paragraph", true);+ const childParagraph = new TestElement("childParagraph", true);+ const childContent = new TestElement("childContent");+ editor.append(list.append(listItem.append(action, paragraph, childParagraph.append(childContent))));++ assert.equal(getBlockDragSelectBlock(asElement(childContent), asElement(editor), getBlock,+ isContainerBlock, isListItem), asElement(childParagraph));+ });++ it("selects the inner list item for its primary content block", () => {+ const editor = new TestElement("editor");+ const outerList = new TestElement("list", true, true);+ const outerListItem = new TestElement("listItem", true, true);+ const outerParagraph = new TestElement("outerParagraph", true);+ const innerList = new TestElement("list", true, true);+ const innerListItem = new TestElement("listItem", true, true);+ const innerAction = new TestElement("innerAction");+ const innerParagraph = new TestElement("innerParagraph", true);+ const content = new TestElement("content");+ innerListItem.append(innerAction, innerParagraph.append(content));+ outerListItem.append(outerParagraph, innerList.append(innerListItem));+ editor.append(outerList.append(outerListItem));++ assert.equal(getBlockDragSelectBlock(asElement(content), asElement(editor), getBlock,+ isContainerBlock, isListItem), asElement(innerListItem));+ });+it("does not cross another container to select an outer list item", () => {const editor = new TestElement("editor");const listItem = new TestElement("listItem", true, true);@@ -187,6 +220,29 @@ describe("resolveBlockDragSelectStart", () => {assert.equal(resolve(new Map([[0, list], [4, list], [8, content]])), asElement(listItem));});+ it("switches from a list item surface to an additional child block", () => {+ const editor = new TestElement("editor");+ const list = new TestElement("list", true, true);+ const listItem = new TestElement("listItem", true, true);+ const paragraph = new TestElement("paragraph", true);+ const childParagraph = new TestElement("childParagraph", true);+ const childContent = new TestElement("childContent");+ editor.append(list.append(listItem.append(paragraph, childParagraph.append(childContent))));+ const isContainerBlock = (element: Element) => (element as unknown as TestElement).containerSurface;+ const isListItem = (element: Element) => (element as unknown as TestElement).name === "listItem";+ const getDragSelectBlock = (element: Element) => getBlockDragSelectBlock(element, asElement(editor),+ getBlock, isContainerBlock, isListItem);++ assert.equal(resolveBlockDragSelectStart({+ x: 100,+ top: 0,+ bottom: 8,+ elementFromPoint: (_x, y) => y < 8 ? asElement(listItem) : asElement(childContent),+ getBlock: getDragSelectBlock,+ isContainerSurface: (element) => (element as unknown as TestElement).containerSurface,+ }), asElement(childParagraph));+ });+["blockquote", "callout", "superBlock"].forEach((name) => {it(`uses the child below a ${name} gap`, () => {const container = new TestElement(name, true, true);diff --git a/app/src/protyle/wysiwyg/blockDragSelect.ts b/app/src/protyle/wysiwyg/blockDragSelect.tsindex 2d3ecf2360..f26712649a 100644--- a/app/src/protyle/wysiwyg/blockDragSelect.ts+++ b/app/src/protyle/wysiwyg/blockDragSelect.ts@@ -31,7 +31,17 @@ export const getBlockDragSelectBlock = (element: Element, boundaryElement: Elemelet parentElement = block.parentElement;while (parentElement && parentElement !== boundaryElement) {if (isContainerBlock(parentElement)) {- return isListItem(parentElement) ? parentElement : block;+ if (!isListItem(parentElement)) {+ return block;+ }+ // 列表项的首个直属块代表列表项主内容,其他子块可单独划选。+ for (let i = 0; i < parentElement.children.length; i++) {+ const childElement = parentElement.children[i];+ if (getBlock(childElement) === childElement) {+ return childElement === block ? parentElement : block;+ }+ }+ return parentElement;}parentElement = parentElement.parentElement;}