@@ -75,6 +75,7 @@ import { trackEvent } from './utils/analytics'
7575import { logger } from './utils/logger'
7676
7777import type { CommandResult } from './commands/command-registry'
78+ import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
7879import type { MultilineInputHandle } from './components/multiline-input'
7980import type { User } from './utils/auth'
8081import type { AgentMode } from './utils/constants'
@@ -669,14 +670,10 @@ export const Chat = ({
669670 ] ,
670671 )
671672
672- // Click handler for slash menu items - executes command immediately
673- const handleSlashItemClick = useCallback (
674- async ( index : number ) => {
675- const selected = slashMatches [ index ]
676- if ( ! selected ) return
677-
678- // If the command has insertText, insert it instead of executing
679- if ( selected . insertText && slashContext . startIndex >= 0 ) {
673+ // Helper to apply insertText for slash commands - returns true if handled
674+ const applySlashInsertText = useCallback (
675+ ( selected : MatchedSlashCommand ) : boolean => {
676+ if ( selected . insertText != null && slashContext . startIndex >= 0 ) {
680677 const before = inputValue . slice ( 0 , slashContext . startIndex )
681678 const after = inputValue . slice (
682679 slashContext . startIndex + 1 + slashContext . query . length ,
@@ -687,8 +684,21 @@ export const Chat = ({
687684 lastEditDueToNav : false ,
688685 } )
689686 setSlashSelectedIndex ( 0 )
690- return
687+ return true
691688 }
689+ return false
690+ } ,
691+ [ slashContext , inputValue , setInputValue , setSlashSelectedIndex ] ,
692+ )
693+
694+ // Click handler for slash menu items - executes command or inserts text
695+ const handleSlashItemClick = useCallback (
696+ async ( index : number ) => {
697+ const selected = slashMatches [ index ]
698+ if ( ! selected ) return
699+
700+ // If the command has insertText, insert it instead of executing
701+ if ( applySlashInsertText ( selected ) ) return
692702
693703 // Execute the selected slash command immediately
694704 const commandString = `/${ selected . id } `
@@ -699,9 +709,7 @@ export const Chat = ({
699709 } ,
700710 [
701711 slashMatches ,
702- slashContext ,
703- inputValue ,
704- setInputValue ,
712+ applySlashInsertText ,
705713 setSlashSelectedIndex ,
706714 onSubmitPrompt ,
707715 agentMode ,
@@ -903,19 +911,7 @@ export const Chat = ({
903911 if ( ! selected ) return
904912
905913 // If the command has insertText, insert it instead of executing
906- if ( selected . insertText && slashContext . startIndex >= 0 ) {
907- const before = inputValue . slice ( 0 , slashContext . startIndex )
908- const after = inputValue . slice (
909- slashContext . startIndex + 1 + slashContext . query . length ,
910- )
911- setInputValue ( {
912- text : before + selected . insertText + after ,
913- cursorPosition : before . length + selected . insertText . length ,
914- lastEditDueToNav : false ,
915- } )
916- setSlashSelectedIndex ( 0 )
917- return
918- }
914+ if ( applySlashInsertText ( selected ) ) return
919915
920916 // Execute the selected slash command immediately
921917 const commandString = `/${ selected . id } `
@@ -929,6 +925,10 @@ export const Chat = ({
929925 // Complete the word without executing - same as clicking on the item
930926 const selected = slashMatches [ slashSelectedIndex ] || slashMatches [ 0 ]
931927 if ( ! selected || slashContext . startIndex < 0 ) return
928+
929+ // If the command has insertText, insert it instead of the command
930+ if ( applySlashInsertText ( selected ) ) return
931+
932932 const before = inputValue . slice ( 0 , slashContext . startIndex )
933933 const after = inputValue . slice (
934934 slashContext . startIndex + 1 + slashContext . query . length ,
@@ -1096,6 +1096,9 @@ export const Chat = ({
10961096 setSlashSelectedIndex ,
10971097 slashMatches ,
10981098 slashSelectedIndex ,
1099+ slashContext ,
1100+ inputValue ,
1101+ applySlashInsertText ,
10991102 onSubmitPrompt ,
11001103 agentMode ,
11011104 handleCommandResult ,
0 commit comments