mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-08 03:07:53 +00:00
feat: add keyboard shortcut for enhance prompt functionality
- Added new command "roo-cline.enhancePrompt" with Ctrl+Shift+E (Cmd+Shift+E on Mac) keybinding - Registered command handler in registerCommands.ts to send message to webview - Added "triggerEnhancePrompt" message type to ExtensionMessage interface - Updated ChatTextArea component to handle keyboard shortcut trigger - Allows users to enhance prompts without clicking the button manually
This commit is contained in:
parent
9fce90be9d
commit
11693986b3
6 changed files with 78 additions and 50 deletions
|
|
@ -53,6 +53,7 @@ export const commandIds = [
|
|||
"focusInput",
|
||||
"acceptInput",
|
||||
"focusPanel",
|
||||
"enhancePrompt",
|
||||
] as const
|
||||
|
||||
export type CommandId = (typeof commandIds)[number]
|
||||
|
|
|
|||
|
|
@ -218,6 +218,15 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
|
|||
|
||||
visibleProvider.postMessageToWebview({ type: "acceptInput" })
|
||||
},
|
||||
enhancePrompt: () => {
|
||||
const visibleProvider = getVisibleProviderOrLog(outputChannel)
|
||||
|
||||
if (!visibleProvider) {
|
||||
return
|
||||
}
|
||||
|
||||
visibleProvider.postMessageToWebview({ type: "triggerEnhancePrompt" })
|
||||
},
|
||||
})
|
||||
|
||||
export const openClineInNewTab = async ({ context, outputChannel }: Omit<RegisterCommandOptions, "provider">) => {
|
||||
|
|
|
|||
|
|
@ -174,6 +174,19 @@
|
|||
"command": "roo-cline.acceptInput",
|
||||
"title": "%command.acceptInput.title%",
|
||||
"category": "%configuration.title%"
|
||||
},
|
||||
{
|
||||
"command": "roo-cline.enhancePrompt",
|
||||
"title": "%command.enhancePrompt.title%",
|
||||
"category": "%configuration.title%"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "roo-cline.enhancePrompt",
|
||||
"key": "ctrl+shift+e",
|
||||
"mac": "cmd+shift+e",
|
||||
"when": "view == roo-cline.SidebarProvider && focusedView == roo-cline.SidebarProvider || activeWebviewPanelId == roo-cline.TabPanelProvider"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
"command.terminal.fixCommand.title": "Fix This Command",
|
||||
"command.terminal.explainCommand.title": "Explain This Command",
|
||||
"command.acceptInput.title": "Accept Input/Suggestion",
|
||||
"command.enhancePrompt.title": "Enhance Prompt",
|
||||
"configuration.title": "Roo Code",
|
||||
"commands.allowedCommands.description": "Commands that can be auto-executed when 'Always approve execute operations' is enabled",
|
||||
"commands.deniedCommands.description": "Command prefixes that will be automatically denied without asking for approval. In case of conflicts with allowed commands, the longest prefix match takes precedence. Add * to deny all commands.",
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ export interface ExtensionMessage {
|
|||
| "codeIndexSecretStatus"
|
||||
| "showDeleteMessageDialog"
|
||||
| "showEditMessageDialog"
|
||||
| "triggerEnhancePrompt"
|
||||
text?: string
|
||||
payload?: any // Add a generic payload for now, can refine later
|
||||
action?:
|
||||
|
|
|
|||
|
|
@ -115,56 +115,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||
return () => document.removeEventListener("mousedown", handleClickOutside)
|
||||
}, [showDropdown])
|
||||
|
||||
// Handle enhanced prompt response and search results.
|
||||
useEffect(() => {
|
||||
const messageHandler = (event: MessageEvent) => {
|
||||
const message = event.data
|
||||
|
||||
if (message.type === "enhancedPrompt") {
|
||||
if (message.text && textAreaRef.current) {
|
||||
try {
|
||||
// Use execCommand to replace text while preserving undo history
|
||||
if (document.execCommand) {
|
||||
// Use native browser methods to preserve undo stack
|
||||
const textarea = textAreaRef.current
|
||||
|
||||
// Focus the textarea to ensure it's the active element
|
||||
textarea.focus()
|
||||
|
||||
// Select all text first
|
||||
textarea.select()
|
||||
document.execCommand("insertText", false, message.text)
|
||||
} else {
|
||||
setInputValue(message.text)
|
||||
}
|
||||
} catch {
|
||||
setInputValue(message.text)
|
||||
}
|
||||
}
|
||||
|
||||
setIsEnhancingPrompt(false)
|
||||
} else if (message.type === "commitSearchResults") {
|
||||
const commits = message.commits.map((commit: any) => ({
|
||||
type: ContextMenuOptionType.Git,
|
||||
value: commit.hash,
|
||||
label: commit.subject,
|
||||
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
|
||||
icon: "$(git-commit)",
|
||||
}))
|
||||
|
||||
setGitCommits(commits)
|
||||
} else if (message.type === "fileSearchResults") {
|
||||
setSearchLoading(false)
|
||||
if (message.requestId === searchRequestId) {
|
||||
setFileSearchResults(message.results || [])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", messageHandler)
|
||||
return () => window.removeEventListener("message", messageHandler)
|
||||
}, [setInputValue, searchRequestId])
|
||||
|
||||
const [isDraggingOver, setIsDraggingOver] = useState(false)
|
||||
const [textAreaBaseHeight, setTextAreaBaseHeight] = useState<number | undefined>(undefined)
|
||||
const [showContextMenu, setShowContextMenu] = useState(false)
|
||||
|
|
@ -218,6 +168,59 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||
|
||||
const allModes = useMemo(() => getAllModes(customModes), [customModes])
|
||||
|
||||
// Handle enhanced prompt response and search results.
|
||||
useEffect(() => {
|
||||
const messageHandler = (event: MessageEvent) => {
|
||||
const message = event.data
|
||||
|
||||
if (message.type === "enhancedPrompt") {
|
||||
if (message.text && textAreaRef.current) {
|
||||
try {
|
||||
// Use execCommand to replace text while preserving undo history
|
||||
if (document.execCommand) {
|
||||
// Use native browser methods to preserve undo stack
|
||||
const textarea = textAreaRef.current
|
||||
|
||||
// Focus the textarea to ensure it's the active element
|
||||
textarea.focus()
|
||||
|
||||
// Select all text first
|
||||
textarea.select()
|
||||
document.execCommand("insertText", false, message.text)
|
||||
} else {
|
||||
setInputValue(message.text)
|
||||
}
|
||||
} catch {
|
||||
setInputValue(message.text)
|
||||
}
|
||||
}
|
||||
|
||||
setIsEnhancingPrompt(false)
|
||||
} else if (message.type === "triggerEnhancePrompt") {
|
||||
// Handle the keyboard shortcut trigger
|
||||
handleEnhancePrompt()
|
||||
} else if (message.type === "commitSearchResults") {
|
||||
const commits = message.commits.map((commit: any) => ({
|
||||
type: ContextMenuOptionType.Git,
|
||||
value: commit.hash,
|
||||
label: commit.subject,
|
||||
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
|
||||
icon: "$(git-commit)",
|
||||
}))
|
||||
|
||||
setGitCommits(commits)
|
||||
} else if (message.type === "fileSearchResults") {
|
||||
setSearchLoading(false)
|
||||
if (message.requestId === searchRequestId) {
|
||||
setFileSearchResults(message.results || [])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", messageHandler)
|
||||
return () => window.removeEventListener("message", messageHandler)
|
||||
}, [setInputValue, searchRequestId, handleEnhancePrompt])
|
||||
|
||||
const queryItems = useMemo(() => {
|
||||
return [
|
||||
{ type: ContextMenuOptionType.Problems, value: "problems" },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue