Skip to content

renderer: fix preedit range width - #12479

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
dobbylee:preedit-range-fix
Apr 27, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
dobbylee:preedit-range-fix

Conversation

@dobbylee

Copy link
Copy Markdown
Member

Related to #12466

Preedit.range() returns an inclusive range, but the end position was calculated as start + w. For wide preedit text, this covers one extra cell.

In Debug builds, Korean IME composition between existing Hangul characters can panic with:
index out of bounds: index 2, len 2

I reproduced this reliably when there are two Hangul characters to the right of the cursor. For example, type 가나다, move the cursor between 가 and 나, then start a new Korean IME composition. With the old range calculation, the renderer skips the first wide character plus the head cell of the next wide character, then resumes on that character's spacer tail.

This changes the inclusive end to start + (w - 1) and adds focused tests for narrow, wide, and right-edge preedit ranges.

This does not fully fix the visual behavior reported in #12466. The adjacent character can still disappear during composition, so this PR only fixes the crash side of the problem.

@dobbylee
dobbylee requested a review from a team as a code owner April 26, 2026 16:57
@ghostty-bot ghostty-bot Bot added the renderer label Apr 26, 2026
@mitchellh mitchellh added this to the 1.3.2 milestone Apr 27, 2026
@mitchellh
mitchellh merged commit 1ed22a5 into ghostty-org:main Apr 27, 2026
91 checks passed
@dobbylee
dobbylee deleted the preedit-range-fix branch April 27, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants