From a7514554e1a577cb879c6d95d41784989801b111 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 5 Jan 2026 12:50:46 +0800 Subject: [PATCH] :recycle: Rename function `code160to32` to `nbsp2space` Signed-off-by: Daniel <845765@qq.com> --- app/src/boot/globalEvent/click.ts | 4 ++-- app/src/mobile/index.ts | 4 ++-- app/src/protyle/gutter/index.ts | 4 ++-- app/src/protyle/header/Title.ts | 8 ++++---- app/src/protyle/util/{code160to32.ts => nbsp2space.ts} | 2 +- app/src/protyle/wysiwyg/index.ts | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) rename app/src/protyle/util/{code160to32.ts => nbsp2space.ts} (63%) diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.ts index bad99e6de..60dd899fa 100644 --- a/app/src/boot/globalEvent/click.ts +++ b/app/src/boot/globalEvent/click.ts @@ -7,7 +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"; +import {nbsp2space} from "../../protyle/util/nbsp2space"; export const globalClickHideMenu = (element: HTMLElement) => { if (!window.siyuan.menus.menu.element.contains(element) && !hasClosestByAttribute(element, "data-menu", "true")) { @@ -43,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 = code160to32(text) // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + text = nbsp2space(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 0486a8852..639ef5d64 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -30,7 +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"; +import {nbsp2space} from "../protyle/util/nbsp2space"; class App { public plugins: import("../plugin").Plugin[] = []; @@ -78,7 +78,7 @@ class App { const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy"); if (copyElement) { let text = copyElement.parentElement.nextElementSibling.textContent.trimEnd(); - text = code160to32(text); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + text = nbsp2space(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/gutter/index.ts b/app/src/protyle/gutter/index.ts index f7c1843ed..7a07df2fe 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -68,7 +68,7 @@ import * as fs from "node:fs"; /// #endif import {checkFold} from "../../util/noRelyPCFunction"; import {clearSelect} from "../util/clear"; -import {code160to32} from "../util/code160to32"; +import {nbsp2space} from "../util/nbsp2space"; export class Gutter { public element: HTMLElement; @@ -1586,7 +1586,7 @@ export class Gutter { element.addEventListener("click", async () => { const hljsElement = nodeElement.querySelector(".hljs") as HTMLElement; let code = hljsElement?.textContent || ""; - code = code160to32(code); + code = nbsp2space(code); // https://github.com/siyuan-note/siyuan/issues/14800 code = code.replace(/\u200D```/g, "```"); diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index a2008d059..7283125b6 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -20,7 +20,7 @@ import {openFileById} from "../../editor/util"; import {setTitle} from "../../dialog/processSystem"; import {getContenteditableElement, getNoContainerElement} from "../wysiwyg/getBlock"; import {commonHotkey} from "../wysiwyg/commonHotkey"; -import {code160to32} from "../util/code160to32"; +import {nbsp2space} from "../util/nbsp2space"; import {genEmptyElement} from "../../block/util"; import {transaction} from "../wysiwyg/transaction"; import {hideTooltip} from "../../dialog/tooltip"; @@ -336,17 +336,17 @@ export class Title { public setTitle(title: string) { /// #if MOBILE if (this.editElement) { - if (code160to32(title) !== code160to32(this.editElement.textContent)) { + if (nbsp2space(title) !== nbsp2space(this.editElement.textContent)) { this.editElement.textContent = title === window.siyuan.languages.untitled ? "" : title; } } else { const inputElement = document.getElementById("toolbarName") as HTMLInputElement; - if (code160to32(title) !== code160to32(inputElement.value)) { + if (nbsp2space(title) !== nbsp2space(inputElement.value)) { inputElement.value = title === window.siyuan.languages.untitled ? "" : title; } } /// #else - if (code160to32(title) !== code160to32(this.editElement.textContent)) { + if (nbsp2space(title) !== nbsp2space(this.editElement.textContent)) { this.editElement.textContent = title === window.siyuan.languages.untitled ? "" : title; } /// #endif diff --git a/app/src/protyle/util/code160to32.ts b/app/src/protyle/util/nbsp2space.ts similarity index 63% rename from app/src/protyle/util/code160to32.ts rename to app/src/protyle/util/nbsp2space.ts index b0a842301..704606471 100644 --- a/app/src/protyle/util/code160to32.ts +++ b/app/src/protyle/util/nbsp2space.ts @@ -1,4 +1,4 @@ -export const code160to32 = (text: string) => { +export const nbsp2space = (text: string) => { // 非打断空格转换为空格 return text.replace(/\u00A0/g, " "); }; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index fec5ff891..21dac5ef2 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -102,7 +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"; +import {nbsp2space} from "../util/nbsp2space"; export class WYSIWYG { public lastHTMLs: { [key: string]: string } = {}; @@ -485,7 +485,7 @@ export class WYSIWYG { html = getEnableHTML(html); } textPlain = textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd(); - textPlain = code160to32(textPlain) // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + textPlain = nbsp2space(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); @@ -2075,7 +2075,7 @@ export class WYSIWYG { textPlain = textPlain.endsWith("\n") ? textPlain.replace(/\n$/, "") : textPlain; } } - textPlain = code160to32(textPlain); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382 + textPlain = nbsp2space(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) {