You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
input: Start each paragraph of a text area at the edge it reads from - #4016
A multi-line Input draws every paragraph from the left, whatever it holds. A paragraph in Arabic or Hebrew should start at the right, the way AppKit's natural alignment does it (NSTextAlignment.natural).
There was also a mismatch: LastLayout::alignment_offset placed the caret and hit-testing by the widest row's width, while paint aligned each row by its own width. With anything other than left alignment, the caret and clicks drifted from the text they belonged to.
Change
A text area's paragraph takes its alignment from its first strong character (UAX Add Scrollbar #9 P2/P3, via unicode_bidi::get_base_direction): right to left starts at the right, anything else at the left. A single-line input and the code editor keep the one text_align they are given.
One function, LineLayout::row_x, places a row. Painting, background, whitespace indicators, the caret, selection and closest_index_for_x all use it, so they can no longer disagree. alignment_offset is gone.
Adds the unicode-bidi dependency (already in the tree through GPUI).
💡 Looks correct and well tested; it adds a direct dependency (unicode-bidi), so the owner needs to accept that before merge.
Reviewed head 942b66e.
Scope / API: No public API change. set_text_align was already single-line only, so text areas never had a user alignment to override; auto-aligning each paragraph by its first strong character (UAX #9 P2/P3) does not take away any existing option. Single-line inputs and the code editor keep text_align.
Correctness:LineLayout::row_x now drives paint, background, whitespace markers, caret, selection, folds and hit-testing, which fixes the real drift between alignment_offset (widest row) and per-row painting for non-left alignment.
Dependency:unicode-bidi 0.3.18 is already in the lock graph through GPUI (+1 line in Cargo.lock, no new crate downloaded), but it becomes a direct dependency of gpui-base.
Note for later: this is per-paragraph natural alignment only; a framework-wide RTL direction (caret movement, component mirroring) remains separate work.
Ran:cargo test -p gpui-base --lib input → 493 passed. Not run visually (no Arabic/Hebrew visual check).
Screenshots of a plain Textarea on macOS, before (main) and after this PR:
Before
After
Arabic paragraphs now start at the right edge; the English paragraph stays at the left.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A multi-line
Inputdraws every paragraph from the left, whatever it holds. A paragraph in Arabic or Hebrew should start at the right, the way AppKit's natural alignment does it (NSTextAlignment.natural).There was also a mismatch:
LastLayout::alignment_offsetplaced the caret and hit-testing by the widest row's width, whilepaintaligned each row by its own width. With anything other than left alignment, the caret and clicks drifted from the text they belonged to.Change
unicode_bidi::get_base_direction): right to left starts at the right, anything else at the left. A single-line input and the code editor keep the onetext_alignthey are given.LineLayout::row_x, places a row. Painting, background, whitespace indicators, the caret, selection andclosest_index_for_xall use it, so they can no longer disagree.alignment_offsetis gone.unicode-bididependency (already in the tree through GPUI).Public API
None. Everything added is
pub(crate).Tests
a_paragraph_starts_at_the_edge_it_reads_from.cargo test -p gpui-base --lib input: 490 passed.cargo clippy -p gpui-base --all-targets -- --deny warningsandcargo fmt --check: clean.