Phenomenon
When a contenteditable element is used with virtual scrolling libraries (e.g., for large documents), the virtual scrolling mechanism may interfere with text selection and caret positioning. The selection may be lost when elements are removed from the DOM during scrolling.
Reproduction example
- Create a contenteditable region with a virtual scrolling library.
- Load a large amount of content.
- Select text in the contenteditable.
- Scroll to trigger virtual scrolling (DOM elements being removed/added).
- Observe whether selection is maintained.
Observed behavior
- In Chrome on macOS, virtual scrolling may cause selection to be lost.
- Caret position may jump when DOM elements are recycled.
- Selection ranges may become invalid.
- Editing may be disrupted during scrolling.
Expected behavior
- Virtual scrolling should not interfere with contenteditable selection.
- Selection should be maintained across DOM updates.
- Or, there should be a standard way to preserve selection during virtual scrolling.