From 950d419b91f084de23b4f4da56ec0d4fec12b4fb Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 4 Jan 2026 21:15:12 +0800 Subject: [PATCH] :art: Clean code Signed-off-by: Daniel <845765@qq.com> --- app/src/boot/globalEvent/click.ts | 3 ++- app/src/mobile/index.ts | 3 ++- app/src/protyle/util/code160to32.ts | 2 +- app/src/protyle/wysiwyg/index.ts | 7 ++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.ts index 99ad6dc14..bad99e6de 100644 --- a/app/src/boot/globalEvent/click.ts +++ b/app/src/boot/globalEvent/click.ts @@ -7,6 +7,7 @@ import {isWindow} from "../../util/functions"; import {writeText} from "../../protyle/util/compatibility"; import {showMessage} from "../../dialog/message"; import {cancelDrag} from "./dragover"; +import {code160to32} from "../../protyle/util/code160to32"; export const globalClickHideMenu = (element: HTMLElement) => { if (!window.siyuan.menus.menu.element.contains(element) && !hasClosestByAttribute(element, "data-menu", "true")) { @@ -42,7 +43,7 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => { const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy"); 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 + text = code160to32(text) // 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); diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index 75e0b36bc..0486a8852 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -30,6 +30,7 @@ import {mobileKeydown} from "./util/keydown"; import {correctHotkey} from "../boot/globalEvent/commonHotkey"; import {processIOSPurchaseResponse} from "../util/iOSPurchase"; import {updateControlAlt} from "../protyle/util/hotKey"; +import {code160to32} from "../protyle/util/code160to32"; class App { public plugins: import("../plugin").Plugin[] = []; @@ -77,7 +78,7 @@ class App { const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy"); if (copyElement) { let text = copyElement.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 = code160to32(text); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 writeText(text); showMessage(window.siyuan.languages.copied, 2000); event.preventDefault(); diff --git a/app/src/protyle/util/code160to32.ts b/app/src/protyle/util/code160to32.ts index d54779e47..b0a842301 100644 --- a/app/src/protyle/util/code160to32.ts +++ b/app/src/protyle/util/code160to32.ts @@ -1,4 +1,4 @@ export const code160to32 = (text: string) => { // 非打断空格转换为空格 - return text.replace(/\u00a0/g, " "); + return text.replace(/\u00A0/g, " "); }; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index d1c7fe0f4..fec5ff891 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -66,7 +66,7 @@ import {openGlobalSearch} from "../../search/util"; import {popSearch} from "../../mobile/menu/search"; /// #endif import {BlockPanel} from "../../block/Panel"; -import {copyPlainText, isInIOS, isMac, isOnlyMeta, readClipboard, encodeBase64} from "../util/compatibility"; +import {copyPlainText, encodeBase64, isInIOS, isMac, isOnlyMeta, readClipboard} from "../util/compatibility"; import {MenuItem} from "../../menus/Menu"; import {fetchPost, fetchSyncPost} from "../../util/fetch"; import {onGet} from "../util/onGet"; @@ -102,6 +102,7 @@ import {openGalleryItemMenu} from "../render/av/gallery/util"; import {clearSelect} from "../util/clear"; import {chartRender} from "../render/chartRender"; import {updateCalloutType} from "./callout"; +import {code160to32} from "../util/code160to32"; export class WYSIWYG { public lastHTMLs: { [key: string]: string } = {}; @@ -484,7 +485,7 @@ export class WYSIWYG { html = getEnableHTML(html); } textPlain = textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd(); - textPlain = textPlain.replace(/\u00A0/g, " ") // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + textPlain = code160to32(textPlain) // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 // Remove ZWSP when copying inline elements https://github.com/siyuan-note/siyuan/issues/13882 .replace(new RegExp(Constants.ZWSP, "g"), ""); event.clipboardData.setData("text/plain", textPlain); @@ -2074,7 +2075,7 @@ export class WYSIWYG { textPlain = textPlain.endsWith("\n") ? textPlain.replace(/\n$/, "") : textPlain; } } - textPlain = textPlain.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + textPlain = code160to32(textPlain); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 event.clipboardData.setData("text/plain", textPlain); if (!isInCodeBlock) {