anomalyco / anomalyco/opencode

TUI prompt Down arrow cannot reach the end of the text

Open
#40,161 0 comments 0 reactions 1 assignee View on GitHub

@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
  1. Run opencode in any directory.
  2. Type Chinese text over three lines: 你好世界, shift+enter, 第二行文字, shift+enter, 第三行.
  3. Put the cursor somewhere in the middle.
  4. Press Down repeatedly.
  5. 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

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.