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: Preserve text selections across callout child blocks https://github.com/siyuan-note/siyuan/issues/18998
Daniele26eb4eb045f
diff --git a/app/src/protyle/wysiwyg/calloutClick.test.ts b/app/src/protyle/wysiwyg/calloutClick.test.tsnew file mode 100644index 0000000000..5dcf87c4fc--- /dev/null+++ b/app/src/protyle/wysiwyg/calloutClick.test.ts@@ -0,0 +1,27 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {isDirectCalloutStructureClick} from "./calloutClick";++describe("isDirectCalloutStructureClick", () => {+ it("accepts a direct click on the callout structure", () => {+ const structure = {} as Element;++ assert.equal(isDirectCalloutStructureClick(structure, structure, structure), true);+ });++ it("rejects a click synthesized after selecting across callout children", () => {+ const structure = {} as Element;+ const firstChild = {} as Element;+ const secondChild = {} as Element;++ assert.equal(isDirectCalloutStructureClick(firstChild, structure, secondChild), false);+ });++ it("rejects a drag that starts or ends outside the callout structure", () => {+ const structure = {} as Element;+ const child = {} as Element;++ assert.equal(isDirectCalloutStructureClick(structure, structure, child), false);+ assert.equal(isDirectCalloutStructureClick(child, structure, structure), false);+ });+});diff --git a/app/src/protyle/wysiwyg/calloutClick.ts b/app/src/protyle/wysiwyg/calloutClick.tsnew file mode 100644index 0000000000..3483e00725--- /dev/null+++ b/app/src/protyle/wysiwyg/calloutClick.ts@@ -0,0 +1,4 @@+export const isDirectCalloutStructureClick = (mouseDownTarget: EventTarget | null,+ clickTarget: EventTarget | null,+ pointerTarget: Element | null) =>+ mouseDownTarget === clickTarget && pointerTarget === clickTarget;diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex f6882fab72..8cef073fa5 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -201,6 +201,7 @@ import {getBlockEdgeCaretRange, isCaretRangeInsideElement} from "./blockEdgeCareimport {LargeListVirtualizer} from "./listVirtualization";import {forEachPluginSubscriber} from "../../plugin/EventBusCore";import {syncRootAttributes} from "../util/syncRootAttributes";+import {isDirectCalloutStructureClick} from "./calloutClick";interface IShiftClickBlockPoint {blockElement: HTMLElement;@@ -351,6 +352,7 @@ export class WYSIWYG {private preventClick: boolean;private preventInput: boolean;private copyAsRichText = false;+ private mouseDownTarget: EventTarget | null = null;private inputTimeout: number;private pendingInputTimeouts = new Map<number, () => void | Promise<void>>();public tableControl: TableControl;@@ -1064,6 +1066,7 @@ export class WYSIWYG {});this.element.addEventListener("mousedown", (event: MouseEvent) => {+ this.mouseDownTarget = event.target;// 常规划选时排除属性占位,三击时恢复以保留浏览器的整段选择行为this.element.classList.toggle("protyle-wysiwyg--select-attr", event.button === 0 && event.detail > 2);if (protyle.toolbar.isMultiSelectMode()) {@@ -4931,19 +4934,23 @@ export class WYSIWYG {// 需在工具栏渲染前记录鼠标释放位置,避免浮层覆盖选区末端const pointerElement = document.elementFromPoint(event.clientX, event.clientY);+ const isDirectCalloutClick = isDirectCalloutStructureClick(this.mouseDownTarget, event.target,+ pointerElement);setTimeout(() => {// 选中后,在选中的文字上点击需等待 range 更新let newRange = getEditorRange(this.element);const calloutElement = ["callout", "callout-info", "callout-content"].some(className =>event.target.classList.contains(className)) ? hasClosestBlock(event.target) : false;const calloutInfoElement = event.target.classList.contains("callout-info") ? event.target : undefined;- if (!protyle.disabled && !event.shiftKey && !ctrlIsPressed && calloutInfoElement) {+ if (!protyle.disabled && !event.shiftKey && !ctrlIsPressed && calloutInfoElement &&+ isDirectCalloutClick) {const calloutTitleElement = calloutInfoElement.querySelector<HTMLElement>(".callout-title");if (calloutTitleElement) {const titleLength = calloutTitleElement.textContent.length;newRange = focusByOffset(calloutTitleElement, titleLength, titleLength) || newRange;}- } else if (!protyle.disabled && !event.shiftKey && !ctrlIsPressed && calloutElement) {+ } else if (!protyle.disabled && !event.shiftKey && !ctrlIsPressed && calloutElement &&+ isDirectCalloutClick) {// 提示块结构区域不可编辑,点击后将光标定位到首个可编辑子块// https://github.com/siyuan-note/siyuan/issues/16310newRange = focusBlock(calloutElement) || newRange;