Repository navigation
Description
Description
Typing space right before '@' when Chinese/CJK/non-ascii characters exist before it causing autocompletion to show up.

And highlighting is broken too, the more Chinese characters occuring before '@', the more tailing character after '@' not correctly highlighted:

Seems to have the same root cause as #3734, The cursor position calculation is a bit messed up when dealing with non-ascii/multi-byte characters.
The problem seems to be related to '@' triggering code here:
https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx#L535
When user input anything, OpenCode will extract the string before cursor to check if it contains an '@' symbol, and check out what follows the '@' symbol, then to decide whether or not to pop up an autocompletion list. The cursor position it fetches is EditBufferRenerable's cursorOffset, which I believe is in display-width(where CJK chars have a length of 2).
// Check if autocomplete should reopen (e.g., after backspace deleted a space)
const offset = props.input().cursorOffset
if (offset === 0) returnBut later cursorOffset was then used as normal string index to get the position of '@' and to slice the search keyword following '@':
// Check for "@" trigger - find the nearest "@" before cursor with no whitespace between
const text = value.slice(0, offset)
const idx = text.lastIndexOf("@")
if (idx === -1) return
const between = text.slice(idx)
const before = idx === 0 ? undefined : value[idx - 1]I find that changing 'text' and 'idx' calculation logic to utilize EditBufferRenderable's API can fix the issue (but my algorithm is very inefficient, getTextRange is already O(n) for iterating over the input text tree, resulting in O(n²) time complexity):
const text = props.input().getTextRange(0, offset)
let idx = -1
for (idx=offset - 1; idx >= 0; idx --) {
const curChar = props.input().getTextRange(idx, idx + 1)
if (curChar === "@") {
break;
}
}
if (idx === -1) return
const between = props.input().getTextRange(idx + 1, offset)
const before = idx === 0 ? undefined : props.input().getTextRange(idx - 1, idx)This algorithm of mine utilizes EditBufferRenderable.getTextRange to get character from input using the correct cursor position. When applied, autocompletion is behaving normally, but highlighting is still broken.
But my algorithm causes severe performance issue. The ideal way to solve this is that OpenTUI's EditBufferRenderable exposing a function like "getting specific character's last display-width offset", within a certain text range. That way we can do something like:
const text = props.input().getTextRange(0, offset)
const idx = props.input().getCharLastOffset("@", 0, offset)
if (idx === -1) return
const between = props.input().getTextRange(idx + 1, offset)
const before = idx === 0 ? undefined : props.input().getTextRange(idx - 1, idx)As for highlighting, it seems to be related to OpenTUI's ExtmarksController's function wrapDeletion and wrapInsertion, having the same issue as stated above, I haven't look into it closely.
Plugins
No response
OpenCode version
1.3.13
Steps to reproduce
- Open OpenCode.
- Paste this character '啊' into prompt input.
- Type '@' and select 'general'.
- Use the mouse to position the cursor over '@'.
- Press space key.
Screenshot and/or share link
Typing space between Chinese character and '@' symbol causing autocompletion to show up:

When typing '@' right after normal ascii letter, autocompletion will not show up as Chinese characters do(possiblly unrelated discovery):


If you managed to position the cursor over '@'(by mouse) when input is pure ascii characters, typing space will not cause autocompletion to show up:

Operating System
Windows 11
Terminal
Windows Terminal
Activity
[-]Inserting space between Chinese characters and '@' causing autocompletion to show up[/-][+]Inserting space between CJK characters and '@' causing autocompletion to show up[/+]XiaoPengYouCode commentedon May 10, 2026
Still reproducible in v1.14.46 on macOS. When Chinese characters precede
@, thecursorOffset(display-width based) gets passed tovalue.slice()as a byte index, causinglastIndexOf('@')to return -1 entirely — so@autocomplete never triggers at all, not just misbehaves.github-actions commentedon Jul 10, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.