🎨 Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382

This commit is contained in:
Daniel 2023-10-09 21:45:36 +08:00
parent 0ed6884761
commit da0fa0853f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 18 additions and 6 deletions

View file

@ -41,7 +41,9 @@ export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
if (copyElement) {
writeText(copyElement.parentElement.nextElementSibling.textContent.trimEnd());
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
writeText(text);
showMessage(window.siyuan.languages.copied, 2000);
event.preventDefault();
return;

View file

@ -64,7 +64,9 @@ class App {
}
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
if (copyElement) {
writeText(copyElement.parentElement.nextElementSibling.textContent.trimEnd());
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
writeText(text);
showMessage(window.siyuan.languages.copied, 2000);
event.preventDefault();
}

View file

@ -394,7 +394,9 @@ const renderPDF = (id: string) => {
return;
}
} else if (target.classList.contains("protyle-action__copy")) {
navigator.clipboard.writeText(target.parentElement.nextElementSibling.textContent.trimEnd());
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
navigator.clipboard.writeText(text);
event.preventDefault();
event.stopPropagation();
break;
@ -626,7 +628,9 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
Protyle.plantumlRender(previewElement, "stage/protyle");
document.querySelectorAll(".protyle-action__copy").forEach((item) => {
item.addEventListener("click", (event) => {
navigator.clipboard.writeText(item.parentElement.nextElementSibling.textContent.trimEnd());
let text = item.parentElement.nextElementSibling.textContent.trimEnd();
text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying
navigator.clipboard.writeText(text);
event.preventDefault();
event.stopPropagation();
})

View file

@ -330,7 +330,9 @@ export class WYSIWYG {
if (protyle.disabled) {
html = getEnableHTML(html);
}
event.clipboardData.setData("text/plain", textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd());
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
event.clipboardData.setData("text/plain", textPlain);
event.clipboardData.setData("text/html", protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/siyuan", html);
});
@ -1245,7 +1247,9 @@ export class WYSIWYG {
}
}
protyle.hint.render(protyle);
event.clipboardData.setData("text/plain", protyle.lute.BlockDOM2StdMd(html).trimEnd()); // 需要 trimEnd否则 \n 会导致 https://github.com/siyuan-note/siyuan/issues/6218
let textPlain = protyle.lute.BlockDOM2StdMd(html).trimEnd(); // 需要 trimEnd否则 \n 会导致 https://github.com/siyuan-note/siyuan/issues/6218
textPlain = textPlain.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
event.clipboardData.setData("text/plain", textPlain);
event.clipboardData.setData("text/html", protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/siyuan", html);
});