BEGINEND
==> `clipboardData.getData("text/plain")` でHTMLを含まないplain textを取得する。
==> `navigator.clipboard.writeText(text)` をテストするには、httpsのサーバーを使う必要がある。
The problem about `navigator.clipboard.writeText(text)` is an async function.
Even if you write a text to clipboard using the `writeText` command inside the paste event,
it won't be pasted in the content editable. because actual writing to the clipboard takes place
after the paste event is finshed and pasting is already done.
It looks like you have to insert the text into the content editable by yourself
instead of letting the browser do it. Well, inserting is possible (see below)
but it does not take care of undoing.
The following code will insert a text into an content-editable
but it won't put it into the undo stack
const selection=window.getSelection();
if(!selection.rangeCount){return;}
selection.deleteFromDocument();
selection.getRangeAt(0).insertNode(document.createTextNode(text));
selection.collapseToEnd();
In constrast to execCommand, this will not modify the browser's undo stack.
This means that you cannot undo the insertion in
a content editable element using Ctrl+Z.
https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
The Clipboard API can be used instead of execCommand in many cases,
but execCommand is still sometimes useful. In particular,
the Clipboard API doesn't replace the insertText command,
which you can use to programmatically replace text at the cursor
while preserving the undo buffer (edit history) in plain
textarea and input elements.