Tk Source Code

View Ticket
Login
Ticket UUID: e7c85cd94175696ef15b9a161128d5644471fba
Title: Revised [text]: right-to-left text is placed in logical order, so the selection, the cursor and clicks are mirrored
Type: Bug Version: revised_text
Submitter: nab Created on: 2026-10-14 15:12:33
Subsystem: 18. [text] Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-14 15:13:31
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-14 15:13:31
Description:

In the revised text widget, the characters of right-to-left text (Hebrew, Arabic) are placed in logical order, while the font system draws them from right to left (macOS, Windows, and X11 with --enable-bidi): bbox, @x,y, the insertion cursor and the selection are mirrored with respect to the glyphs, and a right-to-left run inside a left-to-right line is not placed between its neighbours as the bidi algorithm wants.

pack [text .t -font {Helvetica 20}]
.t insert end "\u05e9\u05dc\u05d5\u05dd \u05e2\u05d5\u05dc\u05dd"
update
foreach i {0 1 2 3} {puts [lindex [.t bbox 1.$i] 0]}

The x of the letters increase: the first letter of the line is at its left end, where the font draws the last one.

Branch nab-text-rtl-layout: the layout resolves the bidi levels of each logical line (UAX #9 with mojibake, paragraph direction from the first strong character), cuts the chunks where the level changes, reorders the chunks of each display line (rule L2) and mirrors the characters of a right-to-left chunk. bbox, @x,y, the cursor, the selection, the underline and the embedded windows and images follow the visual order; a right-to-left stretch is drawn aligned on its right side. Tests textDisp-46.1 to 46.15, red without the fix except the guard 46.12. Checked on macOS, Windows (with ecfcec3a40, merged into trunk) and X11 with --enable-bidi.

Not done: the horizontal bevels of a relief on a reordered line; a logical line joined by elided newlines is not reordered; elided text counts in the bidi resolution.

User Comments: nab added on 2026-10-14 15:13:31:

Merged into revised_text: [371cf58a3ed620a7f52c9346544a0d039ccbedaa|371cf58a3e].