Skip to content

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

:recycle: Rename function `code160to32` to `nbsp2space`

Daniela7514554e1a5
diff --git a/app/src/boot/globalEvent/click.ts b/app/src/boot/globalEvent/click.ts
index bad99e6de4..60dd899fa3 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 0486a88521..639ef5d644 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 f7c1843edf..7a07df2fef 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 a2008d0593..7283125b6e 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 b0a8423015..7046064715 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 fec5ff8919..21dac5ef2d 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) {