Skip to content

editor: fix RTL paragraph alignment + cursor placement (follow-up to #12)#15

Merged
clackups merged 1 commit into
clackups:mainfrom
jrdntnnr:rtl-bidi
Jun 11, 2026
Merged

editor: fix RTL paragraph alignment + cursor placement (follow-up to #12)#15
clackups merged 1 commit into
clackups:mainfrom
jrdntnnr:rtl-bidi

Conversation

@jrdntnnr

Copy link
Copy Markdown
Contributor

What this does

Follow-up to #12: fixes RTL paragraph alignment and cursor placement so Hebrew text behaves correctly in the editor.

  • Alignment — LVGL's per-object base_dir defaults to LTR, so LV_TEXT_ALIGN_AUTO always resolved to left and Hebrew rendered left-aligned. Setting LV_BASE_DIR_AUTO on 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.
  • Cursorlv_label_get_letter_pos is 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.
  • Touchui_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.

Adds a shared utf8_first_strong_dir() helper and a kb_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.

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