Tk Source Code

View Ticket
Login
Ticket UUID: 6b050ba285814dc1d7973df19dba90b2677869f1
Title: Line break inside a grapheme cluster at the end of the text
Type: Bug Version: trunk
Submitter: nab Created on: 2026-10-08 07:41:17
Subsystem: 18. [text] Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-08 11:38:54
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-08 11:38:54
Description:

BoundaryFromState() in generic/tkTextGrapheme.c computes a boundary as the index of mojibake minus the length of the current code point. At the end of the text, mojibake returns an index one past the length, with the last code point as the current one, so the last boundary is placed before the last code point instead of at the end. mojibake_grapheme_next() and mojibake_grapheme_prev() then return a boundary inside the last grapheme cluster of their buffer, and the grapheme-safe cut of TkTextCharLayoutProc relies on them.

Example: with -wrap char or -wrap word, a text widget one character wide shows the emoji woman + ZWJ + laptop (U+1F469 U+200D U+1F4BB) on two lines, cut between the ZWJ and the laptop. The same happens to "e" + U+0301 at the end of a buffer.

Proposed fix: branch nab-grapheme-end, check-in 14c351254c: the boundary at the end of the text is the length of the text. New tests textDisp-39.1 and 39.2 fail before the fix. The text, entry, spinbox and label tests pass (2419, 0).

The same fix is in revised_text 2d3cc2e0ff.

Checked on macOS (aqua) only.

User Comments: nab added on 2026-10-08 11:38:54:

Merged into trunk in [928c0d5297|928c0d5297]. Thanks for testing on X11 and Windows. No backport is needed: this code only exists in trunk.


kevin_walzer added on 2026-10-08 11:16:11:
textDisp-39.1 and textDisp-39.2 pass on X11 and Windows with this branch installed. Feel free to merge to trunk.