Case ce-0130-selection-invalid-after-wrap · Scenario scenario-selection-restoration

Selection becomes invalid after wrapping content in elements

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

Phenomenon

When programmatically wrapping selected content in a new element (e.g., applying bold by wrapping in <b>), the selection range becomes invalid in Firefox. The cursor position is lost.

Reproduction example

  1. Select some text
  2. Programmatically wrap it in a <b> element
  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 wrapping
  • Cursor should be positioned correctly
  • 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 wrapping
  • Restore selection after wrapping
  • Use Range API to maintain valid selection
  • Handle invalid selection gracefully
Before
Hello World Test
Text selected (World highlighted)
After Wrap (Bug)
Hello World Test
After wrapping with &lt;b&gt;, selection range invalidated, cursor position lost
vs
✅ Expected
Hello World| Test
Expected: Selection range maintained, cursor maintained at correct position

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.