@@ -49,7 +49,12 @@ export function Autocomplete(props: {
4949 } )
5050 const filter = createMemo ( ( ) => {
5151 if ( ! store . visible ) return
52- return props . value . substring ( store . index + 1 ) . split ( " " ) [ 0 ]
52+ // Track props.value to make memo reactive to text changes
53+ props . value // <- there surely is a better way to do this, like making .input() reactive
54+
55+ const val = props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . visualCursor . offset + 1 )
56+
57+ return val
5358 } )
5459
5560 function insertPart ( text : string , part : PromptInfo [ "parts" ] [ number ] ) {
@@ -70,7 +75,7 @@ export function Autocomplete(props: {
7075
7176 const virtualText = "@" + text
7277 const extmarkStart = store . index
73- const extmarkEnd = extmarkStart + virtualText . length
78+ const extmarkEnd = extmarkStart + Bun . stringWidth ( virtualText )
7479
7580 const styleId =
7681 part . type === "file"
@@ -364,7 +369,7 @@ export function Autocomplete(props: {
364369 return store . visible
365370 } ,
366371 onInput ( value : string ) {
367- if ( store . visible && value . length <= store . index ) hide ( )
372+ if ( store . visible && Bun . stringWidth ( value ) <= store . index ) hide ( )
368373 } ,
369374 onKeyDown ( e : KeyEvent ) {
370375 if ( store . visible ) {
@@ -378,7 +383,10 @@ export function Autocomplete(props: {
378383 if ( e . name === "@" ) {
379384 const cursorOffset = props . input ( ) . visualCursor . offset
380385 const charBeforeCursor =
381- cursorOffset === 0 ? undefined : props . value . at ( cursorOffset - 1 )
386+ cursorOffset === 0
387+ ? undefined
388+ : props . input ( ) . getTextRange ( cursorOffset - 1 , cursorOffset )
389+
382390 if (
383391 charBeforeCursor === " " ||
384392 charBeforeCursor === "\n" ||
0 commit comments