@@ -42,6 +42,17 @@ import { ContextMenuOptionType, SearchResult } from "@/utils/context-mentions"
4242import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
4343import { CloudAccountSwitcher } from "../cloud/CloudAccountSwitcher"
4444import { ChatContextBar } from "./ChatContextBar"
45+ import { escapeSpaces } from "@/utils/path-mentions"
46+
47+ // Utility function for normalizing directory paths
48+ const normalizeDirectoryPath = ( path : string ) : string => {
49+ // Ensure directories have exactly one trailing slash
50+ if ( path . endsWith ( "/" ) ) {
51+ // Remove multiple trailing slashes and add exactly one
52+ return path . replace ( / \/ + $ / , "/" )
53+ }
54+ return path
55+ }
4556
4657type ChatTextAreaProps = {
4758 inputValue : string
@@ -338,7 +349,7 @@ export const ChatTextArea = forwardRef<LexicalEditor, ChatTextAreaProps>(
338349 . filter ( ( path ) => ! openedTabs . some ( ( tab ) => tab . path && "/" + tab . path === path ) )
339350 . map ( ( path ) => ( {
340351 type : path . endsWith ( "/" ) ? ContextMenuOptionType . Folder : ContextMenuOptionType . File ,
341- value : path ,
352+ value : path . endsWith ( "/" ) ? normalizeDirectoryPath ( path ) : path ,
342353 } ) ) ,
343354 ]
344355 } , [ filePaths , gitCommits , openedTabs ] )
@@ -413,13 +424,7 @@ export const ChatTextArea = forwardRef<LexicalEditor, ChatTextAreaProps>(
413424 setSelectedMenuIndex ( - 1 )
414425 setInputValue ( "" )
415426 setShowContextMenu ( false )
416- if ( type === ContextMenuOptionType . Command && value ) {
417- setSelectedMenuIndex ( - 1 )
418- setShowContextMenu ( false )
419- mentionPluginRef . current ?. insertMention ( value , "/" , ContextMenuOptionType . Command )
420- return
421- }
422- setInputValue ( commandMention + " " )
427+ setInputValue ( value + " " )
423428 return
424429 }
425430
@@ -444,7 +449,12 @@ if (type === ContextMenuOptionType.Command && value) {
444449 let insertValue = value || ""
445450
446451 if ( type === ContextMenuOptionType . File || type === ContextMenuOptionType . Folder ) {
447- insertValue = value || ""
452+ // Escape spaces in file/folder paths and normalize directory paths
453+ let processedValue = value || ""
454+ if ( type === ContextMenuOptionType . Folder ) {
455+ processedValue = normalizeDirectoryPath ( processedValue )
456+ }
457+ insertValue = escapeSpaces ( processedValue )
448458 } else if ( type === ContextMenuOptionType . Problems ) {
449459 insertValue = "problems"
450460 } else if ( type === ContextMenuOptionType . Terminal ) {
@@ -508,8 +518,8 @@ if (type === ContextMenuOptionType.Command && value) {
508518 } else if ( type === "terminal" ) {
509519 serializedText += "@terminal"
510520 } else {
511- // File or folder mention
512- serializedText += `@${ value } `
521+ const escapedValue = escapeSpaces ( value )
522+ serializedText += `@${ escapedValue } `
513523 }
514524 } else if ( trigger === "/" ) {
515525 // Command mention
0 commit comments