File tree Expand file tree Collapse file tree
packages/opencode/src/cli/cmd/tui/component/prompt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,15 +53,7 @@ export function Autocomplete(props: {
5353 // Track props.value to make memo reactive to text changes
5454 props . value // <- there surely is a better way to do this, like making .input() reactive
5555
56- const val = props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . cursorOffset + 1 )
57-
58- // If the filter contains a space, hide the autocomplete
59- if ( val . includes ( " " ) ) {
60- hide ( )
61- return undefined
62- }
63-
64- return val
56+ return props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . cursorOffset )
6557 } )
6658
6759 function insertPart ( text : string , part : PromptInfo [ "parts" ] [ number ] ) {
@@ -387,17 +379,19 @@ export function Autocomplete(props: {
387379 get visible ( ) {
388380 return store . visible
389381 } ,
390- onInput ( ) {
382+ onInput ( value ) {
391383 if ( store . visible ) {
392- if ( props . input ( ) . cursorOffset <= store . index ) {
384+ if (
385+ // Typed text before the trigger
386+ props . input ( ) . cursorOffset <= store . index ||
387+ // There is a space between the trigger and the cursor
388+ props . input ( ) . getTextRange ( store . index , props . input ( ) . cursorOffset ) . match ( / \s / ) ||
389+ // "/<command>" is not the sole content
390+ ( store . visible === "/" && value . match ( / ^ \S + \s + \S + \s * $ / ) )
391+ ) {
393392 hide ( )
394393 return
395394 }
396- // Check if a space was typed after the trigger character
397- const currentText = props . input ( ) . getTextRange ( store . index + 1 , props . input ( ) . cursorOffset + 1 )
398- if ( currentText . includes ( " " ) ) {
399- hide ( )
400- }
401395 }
402396 } ,
403397 onKeyDown ( e : KeyEvent ) {
You can’t perform that action at this time.
0 commit comments