Skip to content

Fix selection.modify() to use resolved text direction instead of inline base direction#357

Open
sambandaru wants to merge 1 commit into
w3c:gh-pagesfrom
sambandaru:gh-pages
Open

Fix selection.modify() to use resolved text direction instead of inline base direction#357
sambandaru wants to merge 1 commit into
w3c:gh-pagesfrom
sambandaru:gh-pages

Conversation

@sambandaru
Copy link
Copy Markdown

@sambandaru sambandaru commented Apr 29, 2026

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.

<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: 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. This change aligns the spec with majority interoperable behavior.


Preview | Diff

Comment thread index.html Outdated
Comment thread index.html Outdated
@sambandaru
Copy link
Copy Markdown
Author

@rniwa Could you please review

@rniwa
Copy link
Copy Markdown
Contributor

rniwa commented May 4, 2026

For normative changes, the following tasks have been completed:

@rniwa
Copy link
Copy Markdown
Contributor

rniwa commented May 4, 2026

Please file bugs for each browser and have this discussed at an editing WG meeting.

@sambandaru sambandaru added the Agenda+ Queue this item for discussion at the next WG meeting label May 5, 2026
@sambandaru
Copy link
Copy Markdown
Author

For normative changes, the following tasks have been completed:

@sambandaru
Copy link
Copy Markdown
Author

Please file bugs for each browser and have this discussed at an editing WG meeting.

Ack

@smaug----
Copy link
Copy Markdown

smaug---- commented May 7, 2026

Are there WPT tests for this?

@sambandaru
Copy link
Copy Markdown
Author

Are there WPT tests for this?

I will add one.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 18, 2026
Tests to support the spec change PR -
w3c/selection-api#357

Bug: 499819853
Change-Id: Ia827a90b9c12f64d04ea72cb2bee8f0535bedd6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7848414
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Pranav Modi <pranavmodi@microsoft.com>
Commit-Queue: Sambamurthy Bandaru <sambamurthy.bandaru@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1631971}
brave-builds pushed a commit to brave/chromium that referenced this pull request May 18, 2026
Tests to support the spec change PR -
w3c/selection-api#357

Bug: 499819853
Change-Id: Ia827a90b9c12f64d04ea72cb2bee8f0535bedd6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7848414
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Pranav Modi <pranavmodi@microsoft.com>
Commit-Queue: Sambamurthy Bandaru <sambamurthy.bandaru@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1631971}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 18, 2026
Tests to support the spec change PR -
w3c/selection-api#357

Bug: 499819853
Change-Id: Ia827a90b9c12f64d04ea72cb2bee8f0535bedd6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7848414
Reviewed-by: Kent Tamura <tkent@chromium.org>
Reviewed-by: Pranav Modi <pranavmodi@microsoft.com>
Commit-Queue: Sambamurthy Bandaru <sambamurthy.bandaru@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1631971}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Agenda+ Queue this item for discussion at the next WG meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants