Skip to content

fix(tui): handle CJK mention autocomplete offsets#26922

Closed
bugisthegod wants to merge 1 commit into
anomalyco:devfrom
bugisthegod:fix/cjk-mention-autocomplete
Closed

fix(tui): handle CJK mention autocomplete offsets#26922
bugisthegod wants to merge 1 commit into
anomalyco:devfrom
bugisthegod:fix/cjk-mention-autocomplete

Conversation

@bugisthegod
Copy link
Copy Markdown

@bugisthegod bugisthegod commented May 11, 2026

Issue for this PR

Closes #26816
Closes #26889
Closes #20852

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes TUI @ mention autocomplete after CJK/wide characters.

cursorOffset is measured in terminal cells, but the previous trigger detection used JS string indexes. With input like 中文 @file, this made the stored @ position too small, so the file query was read from the wrong offset.

This uses getTextRange() plus Bun.stringWidth() so the stored trigger index stays in terminal-cell coordinates. The existing trigger rule is preserved: @ only opens autocomplete at the start of input or after whitespace.

How did you verify your code works?

  • bun test /Users/abel/Documents/Code/opencode-dev/packages/opencode/test/cli/cmd/tui/prompt-autocomplete.test.ts
  • cd packages/opencode && bun typecheck
  • Manually verified 中文 @... can trigger file autocomplete in the TUI.

Screenshots / recordings

Recording.at.2026-05-11.17.34.11.mp4

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

osamu2001 pushed a commit to osamu2001/opencode that referenced this pull request May 12, 2026
String.length counts code points, not display columns, so CJK
characters and emoji that occupy two terminal cells caused
misaligned cursors, broken mention triggers, and incorrect
history restoration offsets.

Use Bun.stringWidth for now, we need an alternative for this.

Fix anomalyco#26716
Close anomalyco#26922
@bugisthegod bugisthegod deleted the fix/cjk-mention-autocomplete branch May 12, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant