fix: keep folder picker open when selecting folders with Tab/Enter

- Modified ChatTextArea.tsx handleMentionSelect to keep menu open for folder selection
- Added special handling for folder paths that updates input with trailing slash
- Updated context-mentions.ts to handle folder paths with trailing slashes
- Allows users to navigate into folders and select nested files via keyboard

Fixes #8076
This commit is contained in:
Roo Code 2025-09-17 17:18:30 +00:00
parent 7b1e3a0ee5
commit 9150fdc1e5
2 changed files with 69 additions and 20 deletions

View file

@ -339,6 +339,48 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
}
}
// Special handling for folder selection - keep menu open and update input
if (type === ContextMenuOptionType.Folder && value) {
// Update the input to show the folder path with trailing slash
const beforeCursor = textAreaRef.current?.value.slice(0, cursorPosition) || ""
const _afterCursor = textAreaRef.current?.value.slice(cursorPosition) || ""
// Find the position of the last '@' symbol before the cursor
const lastAtIndex = beforeCursor.lastIndexOf("@")
if (lastAtIndex !== -1) {
// Replace everything after @ with the folder path
const beforeMention = textAreaRef.current?.value.slice(0, lastAtIndex) || ""
// Add folder path with trailing slash to allow continued typing
const folderPath = value.endsWith("/") ? value : value + "/"
const newValue = beforeMention + "@" + folderPath
setInputValue(newValue)
const newCursorPosition = newValue.length
setCursorPosition(newCursorPosition)
setIntendedCursorPosition(newCursorPosition)
// Update search query to the folder path to show its contents
setSearchQuery(folderPath)
setSelectedType(ContextMenuOptionType.Folder)
// Request folder contents from the extension
vscode.postMessage({
type: "searchFiles",
query: folderPath,
requestId: Math.random().toString(36).substring(2, 9),
})
// Focus the textarea but keep menu open
setTimeout(() => {
if (textAreaRef.current) {
textAreaRef.current.focus()
}
}, 0)
return
}
}
setShowContextMenu(false)
setSelectedType(null)
@ -347,7 +389,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (type === ContextMenuOptionType.URL) {
insertValue = value || ""
} else if (type === ContextMenuOptionType.File || type === ContextMenuOptionType.Folder) {
} else if (type === ContextMenuOptionType.File) {
insertValue = value || ""
} else if (type === ContextMenuOptionType.Problems) {
insertValue = "problems"

View file

@ -259,28 +259,35 @@ export function getContextMenuOptions(
]
}
// Special handling for folder paths - if query ends with /, we're looking inside a folder
const isLookingInsideFolder = query.endsWith("/")
// const _folderPath = isLookingInsideFolder ? query.slice(0, -1) : ""
const lowerQuery = query.toLowerCase()
const suggestions: ContextMenuQueryItem[] = []
// Check for top-level option matches
if ("git".startsWith(lowerQuery)) {
suggestions.push({
type: ContextMenuOptionType.Git,
label: "Git Commits",
description: "Search repository history",
icon: "$(git-commit)",
})
} else if ("git-changes".startsWith(lowerQuery)) {
suggestions.push(workingChanges)
}
if ("problems".startsWith(lowerQuery)) {
suggestions.push({ type: ContextMenuOptionType.Problems })
}
if ("terminal".startsWith(lowerQuery)) {
suggestions.push({ type: ContextMenuOptionType.Terminal })
}
if (query.startsWith("http")) {
suggestions.push({ type: ContextMenuOptionType.URL, value: query })
// Only show top-level options if we're not looking inside a folder
if (!isLookingInsideFolder) {
// Check for top-level option matches
if ("git".startsWith(lowerQuery)) {
suggestions.push({
type: ContextMenuOptionType.Git,
label: "Git Commits",
description: "Search repository history",
icon: "$(git-commit)",
})
} else if ("git-changes".startsWith(lowerQuery)) {
suggestions.push(workingChanges)
}
if ("problems".startsWith(lowerQuery)) {
suggestions.push({ type: ContextMenuOptionType.Problems })
}
if ("terminal".startsWith(lowerQuery)) {
suggestions.push({ type: ContextMenuOptionType.Terminal })
}
if (query.startsWith("http")) {
suggestions.push({ type: ContextMenuOptionType.URL, value: query })
}
}
// Add exact SHA matches to suggestions