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 the first heading when pasting selected blocks https://github.com/siyuan-note/siyuan/issues/18513
Daniel24d80fc538ed
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex 6ae6ac00ae..84eba50db4 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -22,6 +22,7 @@ import {updateTransaction} from "../wysiwyg/transaction";import * as dayjs from "dayjs";import {updateListOrder} from "../wysiwyg/list";import {refreshSbAndPersistWidth} from "../../block/util";+import {hasBlockSelectionPasteMarker} from "./pasteSource";export const beforePaste = (protyle: IProtyle, blockElement: HTMLElement) => {// 链接,备注,样式,引用,pdf标注粘贴 https://github.com/siyuan-note/siyuan/issues/11572@@ -659,6 +660,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven} else {tempElement.innerHTML = siyuanHTML;}+ const isBlockSelectionPaste = hasBlockSelectionPasteMarker(tempElement.children);const startRangeBlockElement = hasClosestBlock(range.startContainer);const endRangeBlockElement = hasClosestBlock(range.endContainer);if (startRangeBlockElement && endRangeBlockElement && startRangeBlockElement !== endRangeBlockElement) {@@ -752,8 +754,8 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven});const hasHeadingChildren = Array.from(tempElement.children).some(item =>item.hasAttribute("parent-heading"));- // 标题及下方块需要保留块类型和折叠关系,交由 insertHTML 处理 https://github.com/siyuan-note/siyuan/issues/18419- if (isBlock && !hasHeadingChildren && pasteCrossBlockRange(protyle, tempElement, range)) {+ // 完整块选择以及标题下方块需要保留块结构,交由 insertHTML 处理 https://github.com/siyuan-note/siyuan/issues/18419+ if (isBlock && !isBlockSelectionPaste && !hasHeadingChildren && pasteCrossBlockRange(protyle, tempElement, range)) {blockRender(protyle, protyle.wysiwyg.element);processRender(protyle.wysiwyg.element);highlightRender(protyle.wysiwyg.element);diff --git a/app/src/protyle/util/pasteSource.test.ts b/app/src/protyle/util/pasteSource.test.tsnew file mode 100644index 0000000000..dfae2657ae--- /dev/null+++ b/app/src/protyle/util/pasteSource.test.ts@@ -0,0 +1,21 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {hasBlockSelectionPasteMarker} from "./pasteSource";++const element = (selected = false) => ({+ classList: {+ contains(className: string) {+ return selected && className === "protyle-wysiwyg--select";+ }+ }+}) as unknown as Element;++describe("hasBlockSelectionPasteMarker", () => {+ it("detects a marker on any pasted root block", () => {+ assert.equal(hasBlockSelectionPasteMarker([element(), element(true)]), true);+ });++ it("does not classify a cross-block text range as a block selection", () => {+ assert.equal(hasBlockSelectionPasteMarker([element(), element()]), false);+ });+});diff --git a/app/src/protyle/util/pasteSource.ts b/app/src/protyle/util/pasteSource.tsnew file mode 100644index 0000000000..9c3e7fca98--- /dev/null+++ b/app/src/protyle/util/pasteSource.ts@@ -0,0 +1,3 @@+export const hasBlockSelectionPasteMarker = (elements: ArrayLike<Element>) => {+ return Array.from(elements).some(item => item.classList.contains("protyle-wysiwyg--select"));+};