An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Fix code block copy issue with ZWJ https://github.com/siyuan-note/siyuan/issues/14800 (#16770)
Jeffrey Chen12456ce23a13
diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.tsindex 0c8d761684..99ad6dc14c 100644--- a/app/src/boot/globalEvent/click.ts+++ b/app/src/boot/globalEvent/click.ts@@ -43,6 +43,8 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {if (copyElement) {let text = copyElement.parentElement.nextElementSibling.textContent.replace(/\n$/, "");text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382+ // https://github.com/siyuan-note/siyuan/issues/14800+ text = text.replace(/\u200D```/g, "```");writeText(text);showMessage(window.siyuan.languages.copied, 2000);event.preventDefault();diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.tsindex 9bea3a382c..f43fa96fda 100644--- a/app/src/protyle/export/index.ts+++ b/app/src/protyle/export/index.ts@@ -51,7 +51,7 @@ export const saveExport = (option: IExportOptions) => {}, zipResponse => {hideMessage(msgId);if (zipResponse.code === -1) {- showMessage(window.siyuan.languages._kernel[14] + ": " + zipResponse.msg, 0, "error");+ showMessage(window.siyuan.languages._kernel[14].replace("%s", zipResponse.msg), 0, "error");return;}window.open(zipResponse.data.zip);@@ -532,6 +532,7 @@ ${getIconScript(servePath)}} else if (target.classList.contains("protyle-action__copy")) {let text = target.parentElement.nextElementSibling.textContent.trimEnd();text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382+ text = text.replace(/\u200D\`\`\`/g, "\`\`\`");navigator.clipboard.writeText(text);event.preventDefault();event.stopPropagation();@@ -825,6 +826,7 @@ ${getIconScript(servePath)}item.addEventListener("click", (event) => {let text = item.parentElement.nextElementSibling.textContent.trimEnd();text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying+ text = text.replace(/\u200D\`\`\`/g, "\`\`\`");navigator.clipboard.writeText(text);event.preventDefault();event.stopPropagation();diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 5c0aeaf050..e8ae1418e7 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -773,7 +773,10 @@ export class Gutter {selectsElement.forEach((item: HTMLElement) => {html += getPlainText(item) + "\n";});- copyPlainText(html.trimEnd());+ let plainText = html.trimEnd();+ // https://github.com/siyuan-note/siyuan/issues/14800+ plainText = plainText.replace(/\u200D```/g, "```");+ copyPlainText(plainText);focusBlock(selectsElement[0]);}}, {@@ -1344,7 +1347,12 @@ export class Gutter {label: window.siyuan.languages.copyPlainText,accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,click() {- copyPlainText(getPlainText(nodeElement as HTMLElement).trimEnd());+ let plainText = getPlainText(nodeElement as HTMLElement).trimEnd();+ if (type === "NodeCodeBlock") {+ // https://github.com/siyuan-note/siyuan/issues/14800+ plainText = plainText.replace(/\u200D```/g, "```");+ }+ copyPlainText(plainText);focusBlock(nodeElement);}}, {diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex 66a51ed738..4f8ef59ae2 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -159,7 +159,7 @@ export const pasteAsPlainText = async (protyle: IProtyle) => {if (getSelection().rangeCount > 0) {const range = getSelection().getRangeAt(0);if (hasClosestByAttribute(range.startContainer, "data-type", "code") || hasClosestByClassName(range.startContainer, "hljs")) {- insertHTML(textPlain.replace(/\u200D```/g, "```").replace(/```/g, "\u200D```"), protyle);+ insertHTML(textPlain.replace(/```/g, "\u200D```"), protyle);return;}}@@ -361,7 +361,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvenif (nodeElement.getAttribute("data-type") === "NodeCodeBlock" ||protyle.toolbar.getCurrentType(range).includes("code")) {// https://github.com/siyuan-note/siyuan/issues/13552- insertHTML(textPlain.replace(/\u200D```/g, "```").replace(/```/g, "\u200D```"), protyle);+ insertHTML(textPlain.replace(/```/g, "\u200D```"), protyle);return;} else if (siyuanHTML) {// 编辑器内部粘贴@@ -439,10 +439,6 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven// 复制 HTML 块粘贴出来的不是 HTML 块 https://github.com/siyuan-note/siyuan/issues/12994tempInnerHTML = Lute.UnEscapeHTMLStr(tempInnerHTML);}-- // https://github.com/siyuan-note/siyuan/issues/13552- tempInnerHTML = tempInnerHTML.replace(/\u200D```/g, "```");-insertHTML(tempInnerHTML, protyle, isBlock, false, true);}blockRender(protyle, protyle.wysiwyg.element);@@ -588,10 +584,6 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven}}}-- // https://github.com/siyuan-note/siyuan/issues/13552- textPlain = textPlain.replace(/\u200D```/g, "```");-const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);insertHTML(textPlainDom, protyle, false, false, true);}diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 5cd2bd88df..d1c7fe0f46 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -469,6 +469,8 @@ export class WYSIWYG {if (isEndOfBlock(range)) {textPlain = textPlain.replace(/\n$/, "");}+ // https://github.com/siyuan-note/siyuan/issues/14800+ textPlain = textPlain.replace(/\u200D```/g, "```");isInCodeBlock = true;} else if (hasClosestByTag(range.startContainer, "TD") || hasClosestByTag(range.startContainer, "TH")) {tempElement.innerHTML = tempElement.innerHTML.replace(/<br>/g, "\n").replace(/<br\/>/g, "\n");@@ -2041,6 +2043,8 @@ export class WYSIWYG {if (hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock") ||hasClosestByTag(range.startContainer, "CODE")) {textPlain = tempElement.textContent.replace(Constants.ZWSP, "");+ // https://github.com/siyuan-note/siyuan/issues/14800+ textPlain = textPlain.replace(/\u200D```/g, "```");isInCodeBlock = true;}// https://github.com/siyuan-note/siyuan/issues/4321