Skip to content

input: Start each paragraph of a text area at the edge it reads from - #4016

Open
Abdulrahman-AlGhamdi wants to merge 1 commit into
longbridge:mainfrom
Abdulrahman-AlGhamdi:text-area-natural-alignment
Open

Abdulrahman-AlGhamdi wants to merge 1 commit into
longbridge:mainfrom
Abdulrahman-AlGhamdi:text-area-natural-alignment

Conversation

@Abdulrahman-AlGhamdi

@Abdulrahman-AlGhamdi Abdulrahman-AlGhamdi commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

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).

Public API

None. Everything added is pub(crate).

Tests

  • New: 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 warnings and cargo fmt --check: clean.

@huacnlee

Copy link
Copy Markdown
Member

💡 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).

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@Abdulrahman-AlGhamdi

Copy link
Copy Markdown
Author

Screenshots of a plain Textarea on macOS, before (main) and after this PR:

Before After
kit-before kit-after

Arabic paragraphs now start at the right edge; the English paragraph stays at the left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants