Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove ZWSP when copying inline elements #14002

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ export class WYSIWYG {
}
// 不能使用 commonAncestorContainer https://ld246.com/article/1643282894693
if (hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock")) {
textPlain = tempElement.textContent.replace(Constants.ZWSP, "").replace(/\n$/, "");
textPlain = tempElement.textContent.replace(new RegExp(Constants.ZWSP, "g"), "").replace(/\n$/, "");
} else if (hasClosestByMatchTag(range.startContainer, "CODE")) {
textPlain = tempElement.textContent.replace(Constants.ZWSP, "");
textPlain = tempElement.textContent.replace(new RegExp(Constants.ZWSP, "g"), "");
} else {
textPlain = range.toString();
}
Expand All @@ -429,6 +429,7 @@ export class WYSIWYG {
}
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
textPlain = textPlain.replace(new RegExp(Constants.ZWSP, "g"), ""); // Remove ZWSP when copying inline elements https://github.com/siyuan-note/siyuan/issues/13882
event.clipboardData.setData("text/plain", textPlain);
event.clipboardData.setData("text/html", selectTableElement ? html : protyle.lute.BlockDOM2HTML(selectAVElement ? textPlain : html));
event.clipboardData.setData("text/siyuan", selectTableElement ? protyle.lute.HTML2BlockDOM(html) : html);
Expand Down