Editor: right-to-left lines align right and move by what is on screen (#134) - #881
Open
fadyehabamer wants to merge 1 commit into
Open
fadyehabamer wants to merge 1 commit into
fadyehabamer wants to merge 1 commit into
Conversation
…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.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #134.
Right-to-left lines now align right, and the arrow keys and Vim
h/lmove the way they point on screen.How
xof- [x] مهمةwould make an Arabic task line left-to-right, which is whatdir="auto"would do. Marks and digits are not strong, so123 שלוםis right-to-left. An explicit LRM/RLM/ALM decides when present.dir="rtl"through a line decoration, which only covers visible lines.EditorView.perLineTextDirectionis enabled, so CodeMirror reads each line's direction: the line aligns right becausetext-alignisstart, and the default arrow-key commands, which are already visual and bidi-aware, move the right way.h/lmove by the same per-line direction, like Vim'srightleft, in normal, visual and operator-pending mode.<Left>/<Right>are mapped too, because Vim forwards them to its built-inh/lwithout remapping.x,<BS>and<Space>stay logical. Registered next toregisterDisplayLineMotionin 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, andbidiExtensionis added next tomarkdownListIndentPluginin every editor surface.Tests
lib/cm-bidi.test.ts, 25 tests:dirattributes, and that they follow editsh/l, counts,<Left>/<Right>anddlin left-to-right and right-to-left linesnpm run test:runin app-core: 2879 passed.tsc --noEmitis clean.Known limits
h/lfollow the line's direction, as the issue suggests. Insert-mode arrow keys use CodeMirror's own visual movement, which handles mixed text fully.padding-leftand the guide backgrounds incm-markdown-list-indent, so I'd keep that as a follow-up.