Skip to content

Commit 1169398

Browse files
committed
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
1 parent 9fce90b commit 1169398

File tree

6 files changed

+78
-50
lines changed

6 files changed

+78
-50
lines changed

packages/types/src/vscode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const commandIds = [
5353
"focusInput",
5454
"acceptInput",
5555
"focusPanel",
56+
"enhancePrompt",
5657
] as const
5758

5859
export type CommandId = (typeof commandIds)[number]

src/activate/registerCommands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
218218

219219
visibleProvider.postMessageToWebview({ type: "acceptInput" })
220220
},
221+
enhancePrompt: () => {
222+
const visibleProvider = getVisibleProviderOrLog(outputChannel)
223+
224+
if (!visibleProvider) {
225+
return
226+
}
227+
228+
visibleProvider.postMessageToWebview({ type: "triggerEnhancePrompt" })
229+
},
221230
})
222231

223232
export const openClineInNewTab = async ({ context, outputChannel }: Omit<RegisterCommandOptions, "provider">) => {

src/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@
174174
"command": "roo-cline.acceptInput",
175175
"title": "%command.acceptInput.title%",
176176
"category": "%configuration.title%"
177+
},
178+
{
179+
"command": "roo-cline.enhancePrompt",
180+
"title": "%command.enhancePrompt.title%",
181+
"category": "%configuration.title%"
182+
}
183+
],
184+
"keybindings": [
185+
{
186+
"command": "roo-cline.enhancePrompt",
187+
"key": "ctrl+shift+e",
188+
"mac": "cmd+shift+e",
189+
"when": "view == roo-cline.SidebarProvider && focusedView == roo-cline.SidebarProvider || activeWebviewPanelId == roo-cline.TabPanelProvider"
177190
}
178191
],
179192
"menus": {

src/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"command.terminal.fixCommand.title": "Fix This Command",
2626
"command.terminal.explainCommand.title": "Explain This Command",
2727
"command.acceptInput.title": "Accept Input/Suggestion",
28+
"command.enhancePrompt.title": "Enhance Prompt",
2829
"configuration.title": "Roo Code",
2930
"commands.allowedCommands.description": "Commands that can be auto-executed when 'Always approve execute operations' is enabled",
3031
"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.",

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface ExtensionMessage {
107107
| "codeIndexSecretStatus"
108108
| "showDeleteMessageDialog"
109109
| "showEditMessageDialog"
110+
| "triggerEnhancePrompt"
110111
text?: string
111112
payload?: any // Add a generic payload for now, can refine later
112113
action?:

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -115,56 +115,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
115115
return () => document.removeEventListener("mousedown", handleClickOutside)
116116
}, [showDropdown])
117117

118-
// Handle enhanced prompt response and search results.
119-
useEffect(() => {
120-
const messageHandler = (event: MessageEvent) => {
121-
const message = event.data
122-
123-
if (message.type === "enhancedPrompt") {
124-
if (message.text && textAreaRef.current) {
125-
try {
126-
// Use execCommand to replace text while preserving undo history
127-
if (document.execCommand) {
128-
// Use native browser methods to preserve undo stack
129-
const textarea = textAreaRef.current
130-
131-
// Focus the textarea to ensure it's the active element
132-
textarea.focus()
133-
134-
// Select all text first
135-
textarea.select()
136-
document.execCommand("insertText", false, message.text)
137-
} else {
138-
setInputValue(message.text)
139-
}
140-
} catch {
141-
setInputValue(message.text)
142-
}
143-
}
144-
145-
setIsEnhancingPrompt(false)
146-
} else if (message.type === "commitSearchResults") {
147-
const commits = message.commits.map((commit: any) => ({
148-
type: ContextMenuOptionType.Git,
149-
value: commit.hash,
150-
label: commit.subject,
151-
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
152-
icon: "$(git-commit)",
153-
}))
154-
155-
setGitCommits(commits)
156-
} else if (message.type === "fileSearchResults") {
157-
setSearchLoading(false)
158-
if (message.requestId === searchRequestId) {
159-
setFileSearchResults(message.results || [])
160-
}
161-
}
162-
}
163-
164-
window.addEventListener("message", messageHandler)
165-
return () => window.removeEventListener("message", messageHandler)
166-
}, [setInputValue, searchRequestId])
167-
168118
const [isDraggingOver, setIsDraggingOver] = useState(false)
169119
const [textAreaBaseHeight, setTextAreaBaseHeight] = useState<number | undefined>(undefined)
170120
const [showContextMenu, setShowContextMenu] = useState(false)
@@ -218,6 +168,59 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
218168

219169
const allModes = useMemo(() => getAllModes(customModes), [customModes])
220170

171+
// Handle enhanced prompt response and search results.
172+
useEffect(() => {
173+
const messageHandler = (event: MessageEvent) => {
174+
const message = event.data
175+
176+
if (message.type === "enhancedPrompt") {
177+
if (message.text && textAreaRef.current) {
178+
try {
179+
// Use execCommand to replace text while preserving undo history
180+
if (document.execCommand) {
181+
// Use native browser methods to preserve undo stack
182+
const textarea = textAreaRef.current
183+
184+
// Focus the textarea to ensure it's the active element
185+
textarea.focus()
186+
187+
// Select all text first
188+
textarea.select()
189+
document.execCommand("insertText", false, message.text)
190+
} else {
191+
setInputValue(message.text)
192+
}
193+
} catch {
194+
setInputValue(message.text)
195+
}
196+
}
197+
198+
setIsEnhancingPrompt(false)
199+
} else if (message.type === "triggerEnhancePrompt") {
200+
// Handle the keyboard shortcut trigger
201+
handleEnhancePrompt()
202+
} else if (message.type === "commitSearchResults") {
203+
const commits = message.commits.map((commit: any) => ({
204+
type: ContextMenuOptionType.Git,
205+
value: commit.hash,
206+
label: commit.subject,
207+
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
208+
icon: "$(git-commit)",
209+
}))
210+
211+
setGitCommits(commits)
212+
} else if (message.type === "fileSearchResults") {
213+
setSearchLoading(false)
214+
if (message.requestId === searchRequestId) {
215+
setFileSearchResults(message.results || [])
216+
}
217+
}
218+
}
219+
220+
window.addEventListener("message", messageHandler)
221+
return () => window.removeEventListener("message", messageHandler)
222+
}, [setInputValue, searchRequestId, handleEnhancePrompt])
223+
221224
const queryItems = useMemo(() => {
222225
return [
223226
{ type: ContextMenuOptionType.Problems, value: "problems" },

0 commit comments

Comments
 (0)