fix: correct terminal display width for Thai sara am and similar SpacingMark characters#2
Conversation
Co-authored-by: admannon <1027194+admannon@users.noreply.github.com>
Co-authored-by: admannon <1027194+admannon@users.noreply.github.com>
|
@copilot "ทำ" should be 2 graphemes not 1 |
Co-authored-by: admannon <1027194+admannon@users.noreply.github.com>
You're right. Thai sara am (ำ) occupies its own terminal column, so "ทำ" should be width 2, not 1. My use of |
… and click detection Co-authored-by: admannon <1027194+admannon@users.noreply.github.com>
Co-authored-by: admannon <1027194+admannon@users.noreply.github.com>
|
@copilot should we use unicode decomposition to determine the width? |
No — NFD decomposition would not help here and would actually break emoji width calculation. Thai sara am (U+0E33) has no canonical decomposition — More critically, NFD breaks emoji: a naive NFD-then-per-code-point sum gives The current hybrid in |
Summary
string-widthv8 usesIntl.Segmenterand treats "ทำ" as a single grapheme cluster (width 1), but Thai sara am (ำ, U+0E33) occupies its own terminal column — correct width is 2.InputPrompt.tsxcalledstringWidth()directly on multi-character strings, causing ghost text wrapping and mouse click detection to be off by 1 column per sara am occurrence.Details
Root cause:
stringWidth("ทำ") === 1(string-width v8, wrong) vsstringWidth("ท") + stringWidth("ำ") === 2(per-code-point, correct). Unicode NFD decomposition is not a viable alternative: Thai sara am (U+0E33) has no canonical decomposition so NFD leaves it unchanged, and a naive NFD-then-per-code-point approach breaks emoji width (e.g.👍🏿→ 4 instead of 2 by expanding skin-tone modifiers).New
getStringDisplayWidth(str)intextUtils.ts— hybrid strategy per grapheme cluster:getCachedStringWidth(cluster)— emoji remain correctly 2InputPrompt.tsx: AllstringWidth(str)calls replaced withgetStringDisplayWidth(str); directstring-widthimport andgetCachedStringWidthimport both removed —InputPrompt.tsxnow depends on onlygetStringDisplayWidthfor all width calculations.Related Issues
How to Validate
ทำงาน) into the input promptทำ— confirm it wraps at the correct columnทำ— confirm click lands on the correct characterPre-Merge Checklist
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.