Skip to content

Commit 09f7e22

Browse files
committed
feat: Add 'roo.acceptInput' command
1 parent 3ffe61f commit 09f7e22

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@
179179
"command": "roo-cline.focusInput",
180180
"title": "%command.focusInput.title%",
181181
"category": "%extension.displayName%"
182+
},
183+
{
184+
"command": "roo.acceptInput",
185+
"title": "%command.acceptInput.title%",
186+
"category": "%extension.displayName%"
182187
}
183188
],
184189
"menus": {

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"command.terminal.explainCommand.title": "Explain This Command",
2424
"command.terminal.fixCommandInCurrentTask.title": "Fix This Command (Current Task)",
2525
"command.terminal.explainCommandInCurrentTask.title": "Explain This Command (Current Task)",
26+
"command.acceptInput.title": "Roo: Accept Input/Suggestion",
2627
"configuration.title": "Roo Code",
2728
"commands.allowedCommands.description": "Commands that can be auto-executed when 'Always approve execute operations' is enabled",
2829
"settings.vsCodeLmModelSelector.description": "Settings for VSCode Language Model API",

src/activate/registerCommands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
117117
"roo-cline.focusInput": () => {
118118
provider.postMessageToWebview({ type: "action", action: "focusInput" })
119119
},
120+
"roo.acceptInput": () => {
121+
const visibleProvider = getVisibleProviderOrLog(outputChannel)
122+
if (!visibleProvider) return
123+
visibleProvider.postMessageToWebview({ type: "acceptInput" })
124+
},
120125
}
121126
}
122127

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface ExtensionMessage {
6969
| "maxReadFileLine"
7070
| "fileSearchResults"
7171
| "toggleApiConfigPin"
72+
| "acceptInput"
7273
text?: string
7374
action?:
7475
| "chatButtonClicked"

webview-ui/src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import TranslationProvider from "./i18n/TranslationContext"
88
import { vscode } from "./utils/vscode"
99
import { telemetryClient } from "./utils/TelemetryClient"
1010
import { ExtensionStateContextProvider, useExtensionState } from "./context/ExtensionStateContext"
11-
import ChatView from "./components/chat/ChatView"
11+
import ChatView, { ChatViewRef } from "./components/chat/ChatView"
1212
import HistoryView from "./components/history/HistoryView"
1313
import SettingsView, { SettingsViewRef } from "./components/settings/SettingsView"
1414
import WelcomeView from "./components/welcome/WelcomeView"
@@ -44,6 +44,7 @@ const App = () => {
4444
})
4545

4646
const settingsRef = useRef<SettingsViewRef>(null)
47+
const chatViewRef = useRef<ChatViewRef>(null)
4748

4849
const switchTab = useCallback((newTab: Tab) => {
4950
setCurrentSection(undefined)
@@ -75,6 +76,10 @@ const App = () => {
7576
const { requestId, promptText } = message
7677
setHumanRelayDialogState({ isOpen: true, requestId, promptText })
7778
}
79+
80+
if (message.type === "acceptInput") {
81+
chatViewRef.current?.acceptInput()
82+
}
7883
},
7984
[switchTab],
8085
)
@@ -114,6 +119,7 @@ const App = () => {
114119
<SettingsView ref={settingsRef} onDone={() => setTab("chat")} targetSection={currentSection} />
115120
)}
116121
<ChatView
122+
ref={chatViewRef}
117123
isHidden={tab !== "chat"}
118124
showAnnouncement={showAnnouncement}
119125
hideAnnouncement={() => setShowAnnouncement(false)}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
22
import debounce from "debounce"
3-
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
3+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react"
44
import { useDeepCompareEffect, useEvent, useMount } from "react-use"
55
import { Virtuoso, type VirtuosoHandle } from "react-virtuoso"
66
import styled from "styled-components"
@@ -40,11 +40,18 @@ interface ChatViewProps {
4040
showHistoryView: () => void
4141
}
4242

43+
export interface ChatViewRef {
44+
acceptInput: () => void
45+
}
46+
4347
export const MAX_IMAGES_PER_MESSAGE = 20 // Anthropic limits to 20 images
4448

4549
const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0
4650

47-
const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryView }: ChatViewProps) => {
51+
const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewProps> = (
52+
{ isHidden, showAnnouncement, hideAnnouncement, showHistoryView },
53+
ref,
54+
) => {
4855
const { t } = useAppTranslation()
4956
const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . ${t("chat:forNextMode")}`
5057
const {
@@ -1162,6 +1169,16 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
11621169
}
11631170
}, [handleKeyDown])
11641171

1172+
useImperativeHandle(ref, () => ({
1173+
acceptInput: () => {
1174+
if (enableButtons && primaryButtonText) {
1175+
handlePrimaryButtonClick(inputValue, selectedImages)
1176+
} else if (!textAreaDisabled && (inputValue.trim() || selectedImages.length > 0)) {
1177+
handleSendMessage(inputValue, selectedImages)
1178+
}
1179+
},
1180+
}))
1181+
11651182
return (
11661183
<div
11671184
style={{
@@ -1386,6 +1403,8 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
13861403
)
13871404
}
13881405

1406+
const ChatView = forwardRef(ChatViewComponent)
1407+
13891408
const ScrollToBottomButton = styled.div`
13901409
background-color: color-mix(in srgb, var(--vscode-toolbar-hoverBackground) 55%, transparent);
13911410
border-radius: 3px;

0 commit comments

Comments
 (0)