Repository navigation
fix: measure terminal columns in cells so CJK text lands correctly - #3
Merged
Merged
Conversation
The editor counted every character as one terminal column. East Asian characters occupy two cells, so the reported cursor column fell short of the real one. The cursor drifted into the middle of the text, and the IME drew its composition overlay at that wrong position, which looked like a duplicated syllable appearing inside what was already typed. Add a cell-width helper and use it wherever a column is measured: the comment layout, the selection wrap, the footer clip, the manager list clip, and vertical cursor motion. Extract the comment layout into its own module so the geometry can be tested.
Contributor
|
thanks, reviewing |
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.
Problem
Typing Korean (or any East Asian text) into the annotation editor puts the cursor in the wrong place, and the character being composed appears to duplicate itself inside the text that is already there.
Both symptoms come from one line.
commentLines()insrc/editor.tsadvances the column by one for every character:East Asian characters occupy two terminal cells. After typing five Hangul syllables the text is ten cells wide, but the editor reports column five and places the cursor there with
\x1b[{row};{col}H. The cursor sits in the middle of the text.The apparent duplication is the same bug seen through the IME. While a syllable is being composed the terminal paints the preedit overlay at the cursor position the application reported, which is mid-text, so the composing syllable shows up inside what was already typed. On commit the application redraws and the syllable jumps to the end.
Fix
Add
src/width.ts, which reports how many cells a character occupies: two for Hangul syllables and jamo, CJK ideographs, kana, fullwidth forms, and emoji, one for the rest, zero for control characters and combining marks.Measure every column in cells rather than characters:
src/layout.ts(extracted fromeditor.ts) computes the cursor row and column in cells, and wraps a line before a wide character would straddle the right edge.wrapText()insrc/format.tswraps on cells, so Korean selections no longer overflow the box.commentLines()moved into its own module becauseeditor.tsstarts the TUI as an import side effect, which leaves the geometry untestable where it was.Tests
15 new tests covering cell widths, comment layout, and wrapping. The full suite is 53 tests, all passing, and
bun run typecheckis clean.Reported and reproduced on macOS with a Korean IME.