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: Restore database mirror copying with hidden titles https://github.com/siyuan-note/siyuan/issues/20083
Daniel61c7ba309222
diff --git a/app/src/protyle/util/blockClipboard.test.ts b/app/src/protyle/util/blockClipboard.test.tsindex 465a2dd7c8..346268498c 100644--- a/app/src/protyle/util/blockClipboard.test.ts+++ b/app/src/protyle/util/blockClipboard.test.ts@@ -70,4 +70,20 @@ describe("block menu clipboard selection", () => {assert.equal(state.focused(), false);assert.equal(state.current(), state.savedRange);});++ for (const platform of ["Win32", "Linux armv8l", "iPhone"]) {+ it(`copies a database through its cursor instead of its hidden title on ${platform}`, () => {+ const state = setup(platform, platform === "Win32" ? 0 : 5);+ const cursor = {focus: () => {}};+ const hiddenTitle = {focus: () => assert.fail("hidden title must not receive focus")};+ state.element.matches = selector => selector === '[data-type="NodeAttributeView"]';+ state.element.querySelector = <T extends Element>(selector: string) =>+ (selector === ".av__cursor" ? cursor : hiddenTitle) as unknown as T;+ copyBlockSelection(state.element, () => {+ assert.equal(state.selected(), cursor);+ assert.equal(state.current(), state.copyRange);+ });+ assert.equal(state.current(), state.savedRange);+ });+ }});diff --git a/app/src/protyle/util/blockClipboard.ts b/app/src/protyle/util/blockClipboard.tsindex b7357b2f2a..755f5b8325 100644--- a/app/src/protyle/util/blockClipboard.ts+++ b/app/src/protyle/util/blockClipboard.ts@@ -1,15 +1,18 @@import {isIOSPlatform} from "./browserCompatibility";export const copyBlockSelection = (element: Element, copy: () => void = () => document.execCommand("copy")) => {- if (!isIOSPlatform(navigator)) {+ const avCursor = element.matches('[data-type="NodeAttributeView"]') ?+ element.querySelector<HTMLElement>(".av__cursor") : null;+ if (!isIOSPlatform(navigator) && !avCursor) {copy();return;}const selection = window.getSelection();const savedRanges = Array.from({length: selection.rangeCount}, (_, index) =>selection.getRangeAt(index).cloneRange());- const editable = element.matches('[contenteditable="true"]') ? element as HTMLElement :- element.querySelector<HTMLElement>('[contenteditable="true"]');+ // 数据库使用专用光标区域,避免隐藏标题使复制事件落在编辑器外。+ const editable = avCursor || (element.matches('[contenteditable="true"]') ? element as HTMLElement :+ element.querySelector<HTMLElement>('[contenteditable="true"]'));const range = document.createRange();// iOS 需要真实的非折叠选区才会触发复制事件,实际复制的块仍由编辑器的块选择状态决定。range.selectNodeContents(editable || element);