Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/8554

Vanessa2b3da2fca489
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index 7eeab676ff..d3202f420c 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -1467,6 +1467,18 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
}
});
orderLists.forEach(orderList => {
+ for (const operation of doOperation) {
+ if (operation.action !== "insert") {
+ continue;
+ }
+ const insertedRoot = orderList.closest(`[data-node-id="${operation.id}"]`);
+ if (!insertedRoot) {
+ continue;
+ }
+ updateListOrder(orderList);
+ operation.data = insertedRoot.outerHTML;
+ return;
+ }
// 保存原有列表项的原始状态用于撤销
const originalItems: {id: string, html: string}[] = [];
orderList.querySelectorAll(":scope > .li").forEach(li => {
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 49040a5b45..362e0e3e66 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -2,6 +2,7 @@ import {
beforePaste,
convertPastedListItemSubtype,
enableLuteMarkdownSyntax,
+ getPlainText,
getTextStar,
paste,
restoreLuteMarkdownSyntax
@@ -783,9 +784,13 @@ export class WYSIWYG {
textPlain = range.toString();
} else {
tempElement.append(range.cloneContents());
- if (nodeElement !== hasClosestBlock(range.endContainer)) {
+ const isCrossBlock = nodeElement !== hasClosestBlock(range.endContainer);
+ if (isCrossBlock) {
this.normalizeCrossBlockCopy(tempElement, range);
}
+ const crossBlockTextPlain = isCrossBlock ? Array.from(tempElement.children)
+ .map(item => getPlainText(item as HTMLElement).trimEnd())
+ .filter(Boolean).join("\n") : undefined;
const textWithoutAttr = this.clearAttrContent(tempElement);
this.emojiToMd(tempElement);
const inlineMathElement = hasClosestByAttribute(range.commonAncestorContainer, "data-type", "inline-math");
@@ -796,7 +801,7 @@ export class WYSIWYG {
html = tempElement.innerHTML;
}
// 不能使用 commonAncestorContainer https://ld246.com/article/1643282894693
- textPlain = tempElement.textContent;
+ textPlain = crossBlockTextPlain ?? tempElement.textContent;
if (hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock")) {
if (isEndOfBlock(range)) {
textPlain = textPlain.replace(/\n$/, "");
@@ -821,7 +826,7 @@ export class WYSIWYG {
}
});
} else if (!hasClosestByTag(range.startContainer, "CODE")) {
- textPlain = textWithoutAttr ?? range.toString();
+ textPlain = crossBlockTextPlain ?? textWithoutAttr ?? range.toString();
}
}
}