Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<div contenteditable>abc<span></span><span></span></div>
<script>
// For emulating the traditional behavior, collapse Selection to end of the
// text node after this <script>.
getSelection().collapse(
document.body.lastChild,
document.body.lastChild.length
);
const editingHost = document.querySelector("div[contenteditable]");
getSelection().collapse(editingHost, 3);
document.execCommand("insertText", false, " ");
</script>
</body>