[w3c/selection-api] Fix selection.modify() to use resolved text direction instead of inline base direction (PR #357)

Steps 7–8 of `Selection.modify()` use the **inline base direction** (paragraph-level CSS `direction`) to map `"left"`/`"right"` to forwards/backwards. This is wrong when the caret is inside a bidi run with a different direction.

```html
<p dir="ltr">Hello שלום world</p>
```

When the caret is inside "שלום" (an RTL run) and the user presses the Right arrow, the current spec maps Right to forwards, and moves the caret visually to the left. This is incorrect. 

The spec should instead use the resolved text direction at the caret (rtl), which maps Right to backwards and moves the caret visually to the right.

**Fix:** Replace "inline base direction" with "resolved text direction at the focus" (bidi embedding level per [UAX#9](https://www.unicode.org/reports/tr9/): even = LTR, odd = RTL).

**Browser behavior:** Firefox and Safari already use resolved text direction. Chromium currently matches the spec text; a [fix is in progress](https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/Editing/bidi-visual-order-caret-movement-explainer.md). This change aligns the spec with majority interoperable behavior.


<!--
    This comment and the below content is programmatically generated.
    You may add a comma-separated list of anchors you'd like a
    direct link to below (e.g. #idl-serializers, #idl-sequence):

    Don't remove this comment or modify anything below this line.
    If you don't want a preview generated for this pull request,
    just replace the whole of this comment's content by "no preview"
    and remove what's below.
-->
***
<a href="https://pr-preview.s3.amazonaws.com/sambandaru/selection-api/pull/357.html" title="Last updated on Apr 29, 2026, 10:57 AM UTC (6aceafa)">Preview</a> | <a href="https://pr-preview.s3.amazonaws.com/w3c/selection-api/357/04da02f...sambandaru:6aceafa.html" title="Last updated on Apr 29, 2026, 10:57 AM UTC (6aceafa)">Diff</a>
You can view, comment on, or merge this pull request online at:

  https://github.com/w3c/selection-api/pull/357

-- Commit Summary --

  * Fix modify() to use resolved text direction instead of inline base direction

-- File Changes --

    M index.html (15)

-- Patch Links --

https://github.com/w3c/selection-api/pull/357.patchhttps://github.com/w3c/selection-api/pull/357.diff
-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/selection-api/pull/357
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/selection-api/pull/357@github.com>

Received on Wednesday, 29 April 2026 10:57:38 UTC