Skip to content

fix: RTL cursor jumping, character loss, and stale alignment#2119

Merged
ra3orblade merged 3 commits into
developfrom
fix/rtl-issues
Apr 29, 2026
Merged

fix: RTL cursor jumping, character loss, and stale alignment#2119
ra3orblade merged 3 commits into
developfrom
fix/rtl-issues

Conversation

@ra3orblade

Copy link
Copy Markdown
Contributor

Summary

  • JS-8716, JS-9183: Save text to store before calling setRtl, so intermediate re-renders from the RTL flag/alignment gRPC calls have the correct text. Previously setRtl ran first, causing re-renders with stale text that led to cursor jumps and first-character deletion when switching between LTR↔RTL.
  • JS-9183, JS-6395: Derive the isRtl CSS class from actual text content (U.String.checkRtl(text)) instead of the stored fields.isRtlDetected flag. The flag lags behind text changes, keeping direction: rtl on the element after the user has already switched to LTR text.
  • JS-6395: Remove the value && guard in setText so that clearing all text properly resets the RTL state. Previously emptying an RTL block kept isRtlDetected=true, so continued LTR typing started with wrong alignment.
  • JS-7255: Already fixed by PR Bugfix/JS-7255: The focus behind the RTL text is moving in a different direction #1898 (merged Jan 16) — issue just needs to be closed.
  • Minor: checkRtl regex now skips leading whitespace so " مرحبا" is correctly detected as RTL.

Fixes

  • JS-6395 — RTL alignment persists when switching to English
  • JS-8716 — Cursor jumping when switching from LTR to RTL
  • JS-9183 — Select all Arabic then type English → cursor precedes text
  • JS-7255 — Focus behind RTL text (already fixed, needs closure)

Test plan

  • Type Arabic text in a block, then delete all and type English — alignment should switch to left
  • Type Arabic, select all, type English — cursor should be in correct position, no character loss
  • Switch keyboard to Arabic in empty block, type first character — character should not be deleted
  • Type several Arabic characters, delete all, verify cursor returns to left side
  • Type text starting with spaces followed by Arabic — should be detected as RTL
  • Undo/redo after switching between RTL and LTR text

🤖 Generated with Claude Code

…S from text content

Three changes to fix RTL cursor jumping, character loss, and stale alignment:

1. In setText, save text to store before calling setRtl. Previously setRtl ran
   first, triggering intermediate re-renders with stale text that caused cursor
   jumps and character loss (JS-8716, JS-9183).

2. Derive the isRtl CSS class from actual text content instead of the stored
   isRtlDetected flag. The flag lags behind text changes, keeping direction:rtl
   on the element after the user switches to LTR text (JS-9183, JS-6395).

3. Remove the `value &&` guard so clearing all text properly resets the RTL
   state. Previously, emptying an RTL block kept isRtlDetected=true, so the
   next block or continued LTR typing started with wrong alignment (JS-6395).

4. Skip leading whitespace in checkRtl so " مرحبا" is correctly detected.

Fixes: JS-6395, JS-8716, JS-9183

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ra3orblade ra3orblade self-assigned this Apr 6, 2026
@ra3orblade
ra3orblade merged commit d0c7cb7 into develop Apr 29, 2026
3 checks passed
@ra3orblade
ra3orblade deleted the fix/rtl-issues branch April 29, 2026 16:10
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant