@@ -52,14 +52,14 @@ export function Autocomplete(props: {
5252 // Track props.value to make memo reactive to text changes
5353 props . value // <- there surely is a better way to do this, like making .input() reactive
5454
55- const val = props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . visualCursor . offset + 1 )
55+ const val = props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . cursorOffset + 1 )
5656
5757 return val
5858 } )
5959
6060 function insertPart ( text : string , part : PromptInfo [ "parts" ] [ number ] ) {
6161 const input = props . input ( )
62- const currentCursorOffset = input . visualCursor . offset
62+ const currentCursorOffset = input . cursorOffset
6363
6464 const charAfterCursor = props . value . at ( currentCursorOffset )
6565 const needsSpace = charAfterCursor !== " "
@@ -344,7 +344,7 @@ export function Autocomplete(props: {
344344 command . keybinds ( false )
345345 setStore ( {
346346 visible : mode ,
347- index : props . input ( ) . visualCursor . offset ,
347+ index : props . input ( ) . cursorOffset ,
348348 position : {
349349 x : props . anchor ( ) . x ,
350350 y : props . anchor ( ) . y ,
@@ -368,8 +368,8 @@ export function Autocomplete(props: {
368368 get visible ( ) {
369369 return store . visible
370370 } ,
371- onInput ( value : string ) {
372- if ( store . visible && Bun . stringWidth ( value ) <= store . index ) hide ( )
371+ onInput ( ) {
372+ if ( store . visible && props . input ( ) . cursorOffset <= store . index ) hide ( )
373373 } ,
374374 onKeyDown ( e : KeyEvent ) {
375375 if ( store . visible ) {
@@ -381,23 +381,20 @@ export function Autocomplete(props: {
381381 }
382382 if ( ! store . visible ) {
383383 if ( e . name === "@" ) {
384- const cursorOffset = props . input ( ) . visualCursor . offset
384+ const cursorOffset = props . input ( ) . cursorOffset
385385 const charBeforeCursor =
386386 cursorOffset === 0
387387 ? undefined
388388 : props . input ( ) . getTextRange ( cursorOffset - 1 , cursorOffset )
389-
390- if (
391- charBeforeCursor === " " ||
392- charBeforeCursor === "\n" ||
393- charBeforeCursor === undefined
394- ) {
395- show ( "@" )
396- }
389+ const canTrigger =
390+ charBeforeCursor === undefined ||
391+ charBeforeCursor === "" ||
392+ / \s / . test ( charBeforeCursor )
393+ if ( canTrigger ) show ( "@" )
397394 }
398395
399396 if ( e . name === "/" ) {
400- if ( props . input ( ) . visualCursor . offset === 0 ) show ( "/" )
397+ if ( props . input ( ) . cursorOffset === 0 ) show ( "/" )
401398 }
402399 }
403400 } ,
0 commit comments