Skip to content

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

:recycle: Remove zero width spaces with the existing string constant https://github.com/siyuan-note/siyuan/issues/20274

Daniel0d888094c5e5
diff --git a/app/src/ai/editor.ts b/app/src/ai/editor.ts
index d44f47bba2..40f34944fd 100644
--- a/app/src/ai/editor.ts
+++ b/app/src/ai/editor.ts
@@ -160,7 +160,7 @@ const isMarkdownInlineElement = (element: Element) => {
};
const sourcePartMarkdown = (protyle: IProtyle, range: Range, editableElement: Element) => {
- const text = range.toString().replace(new RegExp(Constants.ZWSP, "g"), "");
+ const text = range.toString().replaceAll(Constants.ZWSP, "");
let fragment: Node = range.cloneContents();
let ancestor = range.commonAncestorContainer.nodeType === Node.ELEMENT_NODE ?
range.commonAncestorContainer as Element : range.commonAncestorContainer.parentElement;
diff --git a/app/src/layout/dock/agent/AgentComposer.ts b/app/src/layout/dock/agent/AgentComposer.ts
index 36fea221d7..a7da3c8b0c 100644
--- a/app/src/layout/dock/agent/AgentComposer.ts
+++ b/app/src/layout/dock/agent/AgentComposer.ts
@@ -315,7 +315,7 @@ export function mountComposer(host: HTMLElement, onSend: () => void, onChange?:
// ↑ 翻历史:仅在空输入或已处于历史浏览时触发
if (enableHistory && event.key === "ArrowUp" && !event.shiftKey) {
- const isEmpty = (wysiwyg.element.textContent || "").replace(new RegExp(Constants.ZWSP, "g"), "").trim() === "";
+ const isEmpty = (wysiwyg.element.textContent || "").replaceAll(Constants.ZWSP, "").trim() === "";
if ((history.isBrowsing() || isEmpty) && history.has()) {
event.preventDefault();
event.stopPropagation();
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index a629aaaa24..34f18b32be 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -644,7 +644,7 @@ export const hintRef = (key: string, protyle: IProtyle, source: THintSource): IH
createItemCount++;
}
response.data.blocks.forEach((item: IBlock) => {
- const name = item.name ? stripSearchMark(escapeSearchHighlight(item.name)) : item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
+ const name = item.name ? stripSearchMark(escapeSearchHighlight(item.name)) : item.refText.replaceAll(Constants.ZWSP, "");
let value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="d">${name}</span>`;
if (source === "search") {
value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="s">${key}${Constants.ZWSP}${name}</span>`;
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index d941341a04..48558602d7 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -721,7 +721,7 @@ export class Hint {
let blockRefHTML;
if (source === "av") {
// av 搜索时需要获取值 https://github.com/siyuan-note/siyuan/issues/12020
- let refText = item.name ? stripSearchMark(escapeSearchHighlight(item.name)) : item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
+ let refText = item.name ? stripSearchMark(escapeSearchHighlight(item.name)) : item.refText.replaceAll(Constants.ZWSP, "");
if (nodeElement) {
refText = escapeHtml(item.ial[Constants.CUSTOM_SY_AV_STATIC_TEXT + nodeElement.getAttribute("data-av-id")] || "") || refText;
}
diff --git a/app/src/protyle/lite/fragmentEditor.ts b/app/src/protyle/lite/fragmentEditor.ts
index 5a77ead304..3e05dfb601 100644
--- a/app/src/protyle/lite/fragmentEditor.ts
+++ b/app/src/protyle/lite/fragmentEditor.ts
@@ -45,7 +45,7 @@ export interface ProtyleLiteFragment {
}
const isEmptyContent = (element: HTMLElement) =>
- (element.textContent || "").replace(new RegExp(Constants.ZWSP, "g"), "").trim() === "";
+ (element.textContent || "").replaceAll(Constants.ZWSP, "").trim() === "";
export const mountProtyleLiteFragment = (host: HTMLElement,
options: ProtyleLiteFragmentOptions = {}): ProtyleLiteFragment => {
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 46f000a99b..935a1273c6 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -507,7 +507,7 @@ export const writeBlockDOMClipboard = async (lute: Lute, blockDOM: string) => {
};
export const copyPlainText = (text: string) => {
- text = text.replace(new RegExp(Constants.ZWSP, "g"), ""); // `复制纯文本` 时移除所有零宽空格 https://github.com/siyuan-note/siyuan/issues/6674
+ text = text.replaceAll(Constants.ZWSP, ""); // `复制纯文本` 时移除所有零宽空格 https://github.com/siyuan-note/siyuan/issues/6674
writeText(text);
};
diff --git a/app/src/protyle/wysiwyg/emptyTextBlock.ts b/app/src/protyle/wysiwyg/emptyTextBlock.ts
index 844def3c1e..d9da47d508 100644
--- a/app/src/protyle/wysiwyg/emptyTextBlock.ts
+++ b/app/src/protyle/wysiwyg/emptyTextBlock.ts
@@ -8,7 +8,7 @@ const isEmptyEditableBlock = (element: Element) => {
}
const contentElement = editableElement.cloneNode(true) as Element;
contentElement.querySelectorAll("br, wbr").forEach(item => item.remove());
- const text = contentElement.textContent.replace(new RegExp(Constants.ZWSP, "g"), "").trim();
+ const text = contentElement.textContent.replaceAll(Constants.ZWSP, "").trim();
return text === "" && contentElement.childElementCount === 0;
};
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index dd3ccb4e7a..9ff5a21f5b 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1170,7 +1170,7 @@ export class WYSIWYG {
textPlain = textPlain || protyle.lute.BlockDOM2StdMd(externalBlockDOM).trimEnd();
textPlain = removeZWJ(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"), "");
+ .replaceAll(Constants.ZWSP, "");
let clipboardText = textPlain;
if (!isInCodeBlock) {
@@ -2147,7 +2147,7 @@ export class WYSIWYG {
setTimeout(() => {
if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0);
- if (stripSemanticMarkersFromRangeText(range).replace(new RegExp(Constants.ZWSP, "g"), "") !== "") {
+ if (stripSemanticMarkersFromRangeText(range).replaceAll(Constants.ZWSP, "") !== "") {
protyle.toolbar.render(protyle, range, {
x: mouseUpEvent.clientX,
y: mouseUpEvent.clientY,
@@ -3608,7 +3608,7 @@ export class WYSIWYG {
}
}
textPlain = removeZWJ(nbsp2space(textPlain)) // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
- .replace(new RegExp(Constants.ZWSP, "g"), "");
+ .replaceAll(Constants.ZWSP, "");
if (!cutClipboardWritten) {
event.clipboardData.setData("text/plain", textPlain);
}
@@ -5469,7 +5469,7 @@ export class WYSIWYG {
focusByRange(newRange);
}
/// #if !MOBILE
- if (stripSemanticMarkersFromRangeText(newRange).replace(new RegExp(Constants.ZWSP, "g"), "") !== "") {
+ if (stripSemanticMarkersFromRangeText(newRange).replaceAll(Constants.ZWSP, "") !== "") {
const paintedRange = formatPainter.paint(protyle, newRange);
if (paintedRange) {
newRange = paintedRange;