editor: fix RTL paragraph alignment + cursor placement (follow-up to #12)#15
Merged
Conversation
Builds on the Hebrew/RTL support from clackups#12. Three issues remained with right-to-left text: - Paragraph alignment: LVGL's per-object base_dir defaults to LTR, so LV_TEXT_ALIGN_AUTO always resolved to left and Hebrew rendered left-aligned. Set base_dir to LV_BASE_DIR_AUTO on the editor line styles so a paragraph's direction (and alignment) follows its first strong character -- Hebrew lines right-align, Latin lines stay left, mixed lines follow whichever leads. - Cursor placement: lv_label_get_letter_pos is bidi-aware, so once the base direction is correct the caret lands on the right visual side. On an empty / whitespace-only line (no strong char -> detected LTR) the caret is parked at the right edge when an RTL keyboard layout is active, so typing Hebrew starts where the text will appear. - Touch mapping: ui_point_to_offset now passes bidi=true to lv_label_get_letter_on so taps on RTL/mixed lines map through LVGL's visual->logical reordering instead of raw byte order. Adds a shared utf8_first_strong_dir() helper (first strong LTR/RTL codepoint) and a kb_layout_is_rtl() query (true for the Hebrew layout); cursor_line_is_rtl() is refactored onto the shared helper. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What this does
Follow-up to #12: fixes RTL paragraph alignment and cursor placement so Hebrew text behaves correctly in the editor.
base_dirdefaults to LTR, soLV_TEXT_ALIGN_AUTOalways resolved to left and Hebrew rendered left-aligned. SettingLV_BASE_DIR_AUTOon the editor line styles makes each paragraph's direction (and alignment) follow its first strong character: Hebrew lines right-align, Latin lines stay left, mixed lines follow whichever leads.lv_label_get_letter_posis bidi-aware, so with the base direction correct the caret lands on the right visual side. On an empty / whitespace-only line (no strong char → detected LTR) the caret is parked at the right edge when an RTL keyboard layout is active, so typing Hebrew starts where the text appears.ui_point_to_offsetnow passesbidi=truetolv_label_get_letter_on, so taps on RTL/mixed lines map through LVGL's visual→logical reordering.Adds a shared
utf8_first_strong_dir()helper and akb_layout_is_rtl()query;cursor_line_is_rtl()is refactored onto the helper.Board-agnostic. Build-verified on ESP-IDF 5.5 (JC3248W535 config). Split out of #14 per maintainer request.