Skip to content

Commit

Permalink
🎨 Replace non-breaking spaces with normal spaces when copying #9382
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 9, 2023
1 parent 0ed6884 commit da0fa08
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/src/boot/globalEvent/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion app/src/mobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 6 additions & 2 deletions app/src/protyle/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
})
Expand Down
8 changes: 6 additions & 2 deletions app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit da0fa08

Please sign in to comment.