After I insert an image to the contenteditable, I notice the ref() can't "catch up" the inserted image to the text.
- Go to: https://codesandbox.io/s/zealous-ardinghelli-b05ph
- Place cursor to text
- Click the "INSERT IMAGE BETWEEN TEXT" button
- Pay attention to the shown
ref()below the button
const insertImgTag = () => {
const image =
'<img class="separator" src="/text-image.png" width="27px" height="19px">';
let sel, range, node;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = window.getSelection().getRangeAt(0);
node = range.createContextualFragment(image);
range.insertNode(node);
}
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().pasteHTML(image);
}
};
notice on the image above, the shown ref() still counts the <img> as one instead of two like the text
