Skip to content

Editor: right-to-left lines align right and move by what is on screen (#134) - #881

Open
fadyehabamer wants to merge 1 commit into
ZenNotes:mainfrom
fadyehabamer:rtl-line-direction
Open

fadyehabamer wants to merge 1 commit into
ZenNotes:mainfrom
fadyehabamer:rtl-line-direction

Conversation

@fadyehabamer

Copy link
Copy Markdown

Fixes #134.

Right-to-left lines now align right, and the arrow keys and Vim h/l move the way they point on screen.

How

  • Per-line direction. Each line takes the direction of its first strong letter. Leading Markdown syntax is skipped first: list markers, task boxes, heading hashes and quote markers. Otherwise the x of - [x] مهمة would make an Arabic task line left-to-right, which is what dir="auto" would do. Marks and digits are not strong, so 123 שלום is right-to-left. An explicit LRM/RLM/ALM decides when present.
  • Rendering and arrow keys. Right-to-left lines get dir="rtl" through a line decoration, which only covers visible lines. EditorView.perLineTextDirection is enabled, so CodeMirror reads each line's direction: the line aligns right because text-align is start, and the default arrow-key commands, which are already visual and bidi-aware, move the right way.
  • Vim. h/l move by the same per-line direction, like Vim's rightleft, in normal, visual and operator-pending mode. <Left>/<Right> are mapped too, because Vim forwards them to its built-in h/l without remapping. x, <BS> and <Space> stay logical. Registered next to registerDisplayLineMotion in each window that sets up Vim: the main editor, quick capture, the floating note and external files.

The new code is in lib/cm-bidi.ts, and bidiExtension is added next to markdownListIndentPlugin in every editor surface.

Tests

lib/cm-bidi.test.ts, 25 tests:

  • direction detection, including Markdown prefixes, mixed lines, digits and marks
  • the rendered dir attributes, and that they follow edits
  • h/l, counts, <Left>/<Right> and dl in left-to-right and right-to-left lines

npm run test:run in app-core: 2879 passed. tsc --noEmit is clean.

Known limits

  • In a line that mixes directions, Vim h/l follow the line's direction, as the issue suggests. Insert-mode arrow keys use CodeMirror's own visual movement, which handles mixed text fully.
  • Nested list indentation and the list guides still sit on the left in a right-to-left list. They come from padding-left and the guide backgrounds in cm-markdown-list-indent, so I'd keep that as a follow-up.

…ZenNotes#134)

Each line takes the direction of its first strong letter, after skipping list markers, task boxes, heading hashes and quote markers, so '- [x] مهمة' is right-to-left too. Right-to-left lines get dir="rtl" and CodeMirror reads the direction per line (perLineTextDirection), so they align right and the arrow keys move visually. In Vim, h/l and <Left>/<Right> follow the same per-line direction, like Vim's 'rightleft'; x, <BS> and <Space> stay logical.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

[Bug] RTL Language Support: Arrow keys/Vim motions (h/l) directionality and text alignment

2 participants