Skip to content

Commit

Permalink
[#66117] remove use of depracated copy API
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Sep 23, 2024
1 parent 2fa327e commit 58f4021
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/hooks/useText.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ const copyHtmlAsRichText = (/** @type {string} */ txt) => {
doc.querySelectorAll("[data-remove]").forEach((n) => n.remove());
const sanitized = doc.body.innerHTML;

const listener = (e) => {
e.clipboardData.setData("text/html", sanitized);
e.clipboardData.setData("text/plain", sanitized);
e.preventDefault();
};
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
navigator.clipboard.write([
new ClipboardItem({
"text/plain": new Blob([sanitized], { type: "text/plain" }),
"text/html": new Blob([sanitized], { type: "text/html" }),
}),
]);
};

export const markdownUpdatedStateEffect = StateEffect.define();
Expand Down

0 comments on commit 58f4021

Please sign in to comment.