Case ce-0149-selection-range-invalid-after-insert · Scenario scenario-selection-restoration

Selection range becomes invalid after inserting content

OS: Windows 11 Device: Desktop or Laptop Any Browser: Firefox 120.0 Keyboard: US Status: draft
selection range insert firefox

Phenomenon

When programmatically inserting content (text, elements) into a contenteditable element in Firefox, the selection range becomes invalid. The cursor position is lost and cannot be restored.

Reproduction example

  1. Select some text
  2. Programmatically insert content at selection
  3. Check selection state

Observed behavior

  • Selection range becomes invalid
  • Cursor position is lost
  • Cannot continue editing at correct position
  • Selection cannot be restored

Expected behavior

  • Selection should remain valid after insertion
  • Cursor should be positioned after inserted content
  • User should be able to continue editing
  • Selection should be restored properly

Browser Comparison

  • Chrome/Edge: Selection generally remains valid
  • Firefox: Selection becomes invalid (this case)
  • Safari: Selection restoration most unreliable

Notes and possible direction for workarounds

  • Save selection before insertion
  • Restore selection after insertion
  • Use Range API to maintain valid selection
  • Handle invalid selection gracefully
Before
Hello World
Selected text (World)
After Insert (Bug)
Hello World New
After programmatic insertion, selection range invalidated, cursor position unclear
vs
✅ Expected
Hello World New
Expected: Selection range valid, cursor positioned after inserted content

Browser compatibility matrix

This matrix shows which browser and OS combinations have documented cases for this scenario. The current case is highlighted. Click on a cell to view other cases.

Current case
Confirmed
Draft
No case documented

All variants (detailed table)

Complete list of all cases for this scenario with full environment details.

Case OS Device Browser Keyboard Status
ce-0110-selection-lost-after-dom-update Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0130-selection-invalid-after-wrap Windows 11 Desktop or Laptop Any Firefox 120.0 US draft
ce-0138-selection-collapse-on-click macOS 14.0 Desktop or Laptop Any Safari 17.0 US draft
ce-0149-selection-range-invalid-after-insert Windows 11 Desktop or Laptop Any Firefox 120.0 US draft
ce-0172-selection-invalid-after-replace Windows 11 Desktop or Laptop Any Safari 17.0 US draft

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: Windows 11
Device: Desktop or Laptop Any
Browser: Firefox 120.0
Keyboard: US
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.