anomalyco / anomalyco/opencode

[Bug] Thai combining marks counted as width 1 — TUI prompt caret jumps while typing Thai

Open
#49,348 0 comments 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Sep 16, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Typing Thai into the TUI prompt makes the input line jump: the caret lands in the wrong column and the line shifts as each vowel/tone mark is typed. The same text renders correctly at the plain PowerShell prompt in the same terminal tab.

Thai vowel/tone marks are zero-width combining characters (Unicode category Mn), but opencode's bundled width calculation counts each as width 1, so the caret/offset math in the prompt is wrong.

Same root cause as #32067 and #21712 (both auto-closed by the stale bot, no fix). Still reproduces on 1.18.31.

Steps to reproduce
  1. Run opencode in Windows Terminal.
  2. Type สวัสดีครับ (Thai Kedmanee layout — no IME composition, characters are committed directly).
  3. The caret/line jumps with each mark; the prompt misaligns.
  4. The same text typed at the PowerShell prompt in the same tab renders correctly.
Evidence

Width function in the 1.18.31 binary (static inspection, not a runtime trace):

for(let h of o){
  let c=h.codePointAt(0);
  if(c<=31||c>=127&&c<=159||c>=768&&c<=879)continue;   // only Combining Diacritical Marks
  switch(Io.eastAsianWidth(h)){
    case"F":case"W":g+=2;break;
    case"A":g+=f;break;
    default:g+=1                                        // Thai marks land here
  }
}

Thai marks are outside 768–879 and eastAsianWidth returns N for them, so each is added as 1:

char codepoint category wcwidth opencode
MAI HAN AKAT U+0E31 Mn 0 1
SARA I/II/UE/UEE/U/UU, PHINTHU U+0E34–U+0E3A Mn 0 1
tone marks / signs U+0E47–U+0E4E Mn 0 1

Bun.stringWidth is also used for prompt offset math (24 call sites), e.g. Bun.stringWidth(n.slice(0,u)).

Suggested fix

Skip Unicode general categories Mn/Mc/Me, or use grapheme-cluster width. Patching only the Thai block would leave Lao, Khmer, Devanagari, Hebrew niqqud and Arabic harakat broken the same way.

Workaround for users: paste the Thai text instead of typing it, or use opencode web.

Plugins

None.

OpenCode version

1.18.31 (current latest on npm)

Operating System

Windows 11 Pro 25H2, build 26200.9168

Terminal

Windows Terminal 1.24.11911.0 (PowerShell 7)

Related
  • #32067 — Thai combining characters miscounted in stringWidth causing TUI prompt misalignment (stale-closed)
  • #21712 — Thai text rendering is broken in TUI (closed)
  • #44338 — TUI: Locale.truncate splits emoji surrogates and under-truncates CJK (open, same class of width bug)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.