admin管理员组文章数量:1433165
I am writing some sort of editor, where only parts are editable. By clicking behind the row, the caret should be placed at the end of the row for some user input.
In FF this works, in chrome it works until you click behind the row twice. The second click will remove the caret. According to the selection object, the current range is still set to the rows text, but if I for example log the range on "click" it is still the same, but in the view the caret is gone and nothing happens on input.
The following example demonstrates with the visible outline, that the selection seems to change to the wrapping parent, which seems not to be reflected in the pages selection state. How can I detect something that is not there / how does the browser know about the other selection but does not give me access to it? is there any workaround for this problem or am I just stranded in the contenteditable rabithole?
document.addEventListener("selectionchange", () => {
console.log(document.getSelection().anchorNode?.nodeName)
});
Not Working
<br>
<div contenteditable>
<div contenteditable="false"><span contenteditable>test</div></span>
<div contenteditable="false"><span contenteditable>test</div></span>
</div>
<br>
Working
<br>
<div contenteditable>
<div><span>test</div></span>
<div><span>test</div></span>
</div>
本文标签:
版权声明:本文标题:javascript - Selection is changed without throwing the selectionchange event inside nested contenteditable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745605950a2665838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论