Fix CJK lines wrapping in the overlay (exact wide-char padding) - #180
Open
cocomode18 wants to merge 2 commits into
Open
Fix CJK lines wrapping in the overlay (exact wide-char padding)#180cocomode18 wants to merge 2 commits into
cocomode18 wants to merge 2 commits into
Conversation
The padding correction for double-width characters used `(line.bytesize - line.size) / 3`, which is tuned for 4-byte emoji and under-counts 3-byte CJK characters. The shortfall over-padded every line containing CJK text, pushing it past the pane width so it wrapped, leaving a blank row beneath each line in the fingers overlay. Replace the heuristic with an exact wide-character count based on the Unicode East Asian Width Wide/Fullwidth ranges plus the common emoji blocks (emoji stay wide, so they are unaffected). Ambiguous-width symbols such as box-drawing and powerline glyphs are deliberately excluded since terminals render them one column wide. Add specs covering CJK padding, exact wide-char counting, and emoji non-regression.
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
In panes containing CJK text, every line wraps in the fingers overlay, leaving a
blank row beneath it — the visible content appears to grow / become double-spaced
the moment fingers is triggered. ASCII-only lines are unaffected.
Root cause
Hinter#process_linepads each rendered line to the pane width, correcting fordouble-width characters with:
This
/3is tuned for 4-byte emoji (3 extra bytes → +1 column) but under-counts3-byte CJK characters: a CJK char has
bytesize - size == 2, so it contributes2/3 ≈ 0.67instead of the1extra column it actually occupies.The correction therefore comes out too small,
padding_amounttoo large, and therendered line exceeds the pane width by ~
N/3columns (N = CJK chars on the line).The terminal wraps it, and the trailing
"\n"then lands a row lower — so eachCJK line consumes two rows. Worked example at width 100:
最終形:- リンク開く → Shift+Cmd+Click …* Crunched for 5s(ASCII)Fix
Count wide characters exactly instead of estimating from byte length, using the
Unicode East Asian Width Wide/Fullwidth ranges plus the common emoji blocks.
Emoji remain wide, so they are unaffected; ambiguous-width symbols (box-drawing,
powerline glyphs) are deliberately excluded because terminals render them one
column wide.
Tests
Adds specs covering CJK line padding (no overflow at the target width), exact
wide-char counting, and emoji non-regression.
crystal spec spec/lib/fingers/hinter_spec.crpasses (6 examples, 0 failures).