Case ce-0033 · Scenario scenario-selection-range-accuracy

Selection range is incorrect when selecting across multiple elements

OS: Windows 11 Device: Desktop or Laptop Any Browser: Edge 120.0 Keyboard: US Status: draft
selection range elements edge

Phenomenon

When selecting text that spans across multiple HTML elements (e.g., <p>, <div>, <span>) in a contenteditable region, the selection range may not accurately reflect the visual selection. The Selection and Range APIs may return incorrect boundaries.

Reproduction example

  1. Create a contenteditable div with nested elements:
    <div contenteditable>
      <p>First paragraph</p>
      <p>Second paragraph</p>
    </div>
  2. Select text that spans from the middle of the first paragraph to the middle of the second paragraph.
  3. Use JavaScript to inspect the selection range.
  4. Observe the reported start and end positions.

Observed behavior

  • In Edge on Windows, the selection range boundaries may not match the visual selection.
  • The Range.startOffset and Range.endOffset may be incorrect.
  • Selecting across element boundaries can produce unexpected results.

Expected behavior

  • The selection range should accurately reflect the visual selection.
  • Boundaries should be correctly reported even when spanning multiple elements.
  • The Selection and Range APIs should provide consistent, reliable data.

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: Edge 120.0
Keyboard: US
Your environment

Use this editable area to reproduce the described case.

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.