fix(tui): handle CJK mention autocomplete offsets#26922
Closed
bugisthegod wants to merge 1 commit into
Closed
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26816
Closes #26889
Closes #20852
Type of change
What does this PR do?
Fixes TUI
@mention autocomplete after CJK/wide characters.cursorOffsetis 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()plusBun.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.tscd packages/opencode && bun typecheck中文 @...can trigger file autocomplete in the TUI.Screenshots / recordings
Recording.at.2026-05-11.17.34.11.mp4
Checklist