An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Resolve database selection roots for kanban cards
Daniel0c13cc197638
diff --git a/app/src/protyle/render/av/selectionState.test.ts b/app/src/protyle/render/av/selectionState.test.tsindex 9477522754..8f931ae8f1 100644--- a/app/src/protyle/render/av/selectionState.test.ts+++ b/app/src/protyle/render/av/selectionState.test.ts@@ -5,6 +5,7 @@ import {findAVItemPointIndex,getAVCellSelection,getAVItemSelection,+ getAVSelectionRoot,reconcileAVSelectedItemIDs,setAVCellSelection,setAVItemAnchorState,@@ -12,6 +13,19 @@ import {} from "./selectionState";describe("database range selection helpers", () => {+ it("resolves the selection root from an item instead of requiring a block ancestor", () => {+ const root = {} as HTMLElement;+ const item = {+ closest: (selector: string) => {+ assert.equal(selector, "[data-av-id][data-av-type]");+ return root;+ },+ } as unknown as HTMLElement;++ assert.equal(getAVSelectionRoot(item), root);+ assert.equal(getAVSelectionRoot(), undefined);+ });+it("locates duplicate items by both group and item ID", () => {const items = [{groupID: "group-a", itemID: "item-1"},diff --git a/app/src/protyle/render/av/selectionState.ts b/app/src/protyle/render/av/selectionState.tsindex 000796c84c..77bafc2f85 100644--- a/app/src/protyle/render/av/selectionState.ts+++ b/app/src/protyle/render/av/selectionState.ts@@ -34,6 +34,9 @@ interface IAVSelectionState {const selectionStates = new WeakMap<HTMLElement, IAVSelectionState>();+export const getAVSelectionRoot = (element?: Element | null) =>+ element?.closest<HTMLElement>("[data-av-id][data-av-type]") || undefined;+export const findAVItemPointIndex = <T extends {itemID: string, groupID: string}>(items: T[], itemID?: string, groupID?: string) => {return items.findIndex(item => item.itemID === itemID && item.groupID === groupID);diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 4e848254c2..0efe65a539 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -152,7 +152,7 @@ import {getTypeByCellElement,updateCellsValue} from "../render/av/cell";-import {getAVSelectedCells} from "../render/av/selectionState";+import {getAVSelectedCells, getAVSelectionRoot} from "../render/av/selectionState";import {openEmojiPanel, unicode2Emoji} from "../../emoji";import {getIconValueKind} from "../../emoji/iconValue";import {escapeAttr, escapeHtml} from "../../util/escape";@@ -1179,6 +1179,7 @@ export class WYSIWYG {const galleryItemElement = hasClosestByClassName(target, "av__gallery-item");const rowElement = hasClosestByClassName(target, "av__row");const avCellElement = hasClosestByClassName(target, "av__cell");+ const avElement = getAVSelectionRoot(target);const wysiwygRect = protyle.wysiwyg.element.getBoundingClientRect();const wysiwygStyle = window.getComputedStyle(protyle.wysiwyg.element);const contentBounds = getBlockDragSelectContentBounds(wysiwygRect.left, wysiwygRect.right,@@ -1199,10 +1200,12 @@ export class WYSIWYG {const openListItemAttrByShift = shouldOpenListItemAttr(event.shiftKey, protyle.disabled,hasClosestByClassName(target, "protyle-action"));if (event.shiftKey && !openListItemAttrByShift) {- if (!isMobile() && !protyle.disabled && nodeElement?.dataset.avType === "table" &&+ if (!isMobile() && !protyle.disabled && avElement?.dataset.avType === "table" &&avCellElement && avCellElement.dataset.id &&- selectAVCellRange(nodeElement, avCellElement)) {- focusBlock(nodeElement);+ selectAVCellRange(avElement, avCellElement)) {+ if (nodeElement) {+ focusBlock(nodeElement);+ }this.preventClick = true;event.preventDefault();event.stopPropagation();@@ -1210,8 +1213,10 @@ export class WYSIWYG {}const itemElement = galleryItemElement ||(rowElement && !rowElement.classList.contains("av__row--header") ? rowElement : false);- if (!hasSelectClassElement && itemElement && selectAVItemRange(nodeElement, itemElement)) {- focusBlock(nodeElement);+ if (!hasSelectClassElement && avElement && itemElement && selectAVItemRange(avElement, itemElement)) {+ if (nodeElement) {+ focusBlock(nodeElement);+ }this.preventClick = true;event.preventDefault();event.stopPropagation();@@ -1243,10 +1248,14 @@ export class WYSIWYG {galleryItemElement.classList.toggle("av__gallery-item--select"));}updateHeader(galleryItemElement);- setAVItemAnchor(nodeElement, galleryItemElement as HTMLElement);+ if (avElement) {+ setAVItemAnchor(avElement, galleryItemElement as HTMLElement);+ }} else if (rowElement) {selectRow(rowElement.querySelector(".av__firstcol"), "toggle");- setAVItemAnchor(nodeElement, rowElement as HTMLElement);+ if (avElement) {+ setAVItemAnchor(avElement, rowElement as HTMLElement);+ }}} else if (ctrlElement) {clearSelect(["img", "row", "galleryItem"], this.element);@@ -1262,7 +1271,8 @@ export class WYSIWYG {}// https://github.com/siyuan-note/siyuan/issues/15100- if (galleryItemElement && !hasClosestByAttribute(target, "data-type", "av-gallery-more")) {+ if (galleryItemElement && avElement &&+ !hasClosestByAttribute(target, "data-type", "av-gallery-more")) {documentSelf.onmouseup = () => {documentSelf.onmousemove = null;documentSelf.onmouseup = null;@@ -1270,7 +1280,7 @@ export class WYSIWYG {documentSelf.onselectstart = null;documentSelf.onselect = null;clearSelect(["galleryItem"], protyle.wysiwyg.element);- setAVItemAnchor(nodeElement, galleryItemElement as HTMLElement);+ setAVItemAnchor(avElement, galleryItemElement as HTMLElement);return false;};return;