anomalyco / anomalyco/opencode
TUI prompt Down arrow cannot reach the end of the text
@kommander is already working on this.
Since Aug 2, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
In the TUI prompt, pressing Down never reaches the end of the text when the prompt contains CJK characters. The cursor bounces between two positions and looks frozen. With pure ASCII text Down works fine, and Up works fine in both cases.
The prompt.history.next command (packages/tui/src/component/prompt/index.tsx:906) compares cursorOffset against input.plainText.length, but cursorOffset is measured in display columns (and a newline counts as 1 column), not UTF-16 length. For 你好世界\n第二行文字\n第三行 the real end offset is 26 while plainText.length is 14. So when the cursor is already at the end, the command decides it is not, sets the offset back to 14 (middle of the text), and the built-in input.move.down then moves it to 25 — repeating forever.
Measured offsets after each Down press, starting from offset 6:
- ASCII
one\ntwo\nthree(end = 13): 5 -> 9 -> 13 -> 13 (fine) - CJK
你好世界\n第二行文字\n第三行(end = 26): 6 -> 15 -> 26 -> 25 -> 25 -> 25 (stuck)
The same class of bug exists in the run-mode composer (packages/opencode/src/cli/cmd/run/footer.prompt.tsx:769), which uses Bun.stringWidth for the end offset. Bun.stringWidth counts a newline as 0, so that one is off by one per newline and fails on plain ASCII multi-line text too.
#27426 reported the same symptom for Korean/Japanese text and was closed as not planned. This report adds the root cause.
Happy to send a PR: use promptOffsetWidth (already in packages/tui/src/prompt/display.ts) instead of plainText.length / Bun.stringWidth, or call the native gotoBufferEnd().
Plugins
No plugins
OpenCode version
1.18.11
Steps to reproduce
- Run
opencodein any directory. - Type Chinese text over three lines:
你好世界, shift+enter,第二行文字, shift+enter,第三行. - Put the cursor somewhere in the middle.
- Press Down repeatedly.
- The cursor stops one position before the end and never advances.
For the run-mode composer, the same happens with plain ASCII: opencode run interactive mode, type one / shift+enter / two / shift+enter / three, then press Down from the middle.
Screenshot and/or share link
No response
Operating System
Ubuntu 24.04.3 LTS (WSL2, kernel 6.6.87.2-microsoft-standard-WSL2)
Terminal
Windows Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.