From d2cbbbe86a9f1f030cf47bebab0bb5dd83853216 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 20 Apr 2025 22:39:52 -0700 Subject: [PATCH] keyboard shortcuts for accept/reject tool calls --- core/package-lock.json | 2 +- gui/package-lock.json | 2 +- gui/src/components/mainInput/InputToolbar.tsx | 29 +----- .../mainInput/InputToolbar/EnterButton.tsx | 29 ++++++ .../components/mainInput/Lump/LumpToolbar.tsx | 58 ++++++++++- gui/src/pages/gui/Chat.tsx | 19 ++-- .../gui/ToolCallDiv/ToolCallButtonsDiv.tsx | 97 ------------------- 7 files changed, 98 insertions(+), 138 deletions(-) create mode 100644 gui/src/components/mainInput/InputToolbar/EnterButton.tsx delete mode 100644 gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx diff --git a/core/package-lock.json b/core/package-lock.json index 0a0e8622b..2536f0d29 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -134,7 +134,7 @@ }, "../packages/config-yaml": { "name": "@continuedev/config-yaml", - "version": "1.0.78", + "version": "1.0.87", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/gui/package-lock.json b/gui/package-lock.json index c47bb8827..c65e604e6 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -206,7 +206,7 @@ }, "../packages/config-yaml": { "name": "@continuedev/config-yaml", - "version": "1.0.78", + "version": "1.0.87", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 08c5a910f..417267188 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -3,14 +3,7 @@ import { InputModifiers } from "core"; import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect"; import { useRef } from "react"; import styled from "styled-components"; -import { - defaultBorderRadius, - lightGray, - vscButtonBackground, - vscButtonForeground, - vscForeground, - vscInputBackground, -} from ".."; +import { vscInputBackground } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseActiveFile } from "../../redux/selectors"; import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall"; @@ -31,6 +24,7 @@ import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; import ModeSelect from "../modelSelection/ModeSelect"; import { useFontSize } from "../ui/font"; +import { EnterButton } from "./InputToolbar/EnterButton"; import HoverItem from "./InputToolbar/HoverItem"; const StyledDiv = styled.div<{ isHidden?: boolean }>` @@ -50,25 +44,6 @@ const StyledDiv = styled.div<{ isHidden?: boolean }>` } `; -const EnterButton = styled.button<{ isPrimary?: boolean }>` - all: unset; - padding: 2px 4px; - display: flex; - align-items: center; - background-color: ${(props) => - !props.disabled && props.isPrimary - ? vscButtonBackground - : lightGray + "33"}; - border-radius: ${defaultBorderRadius}; - color: ${(props) => - !props.disabled && props.isPrimary ? vscButtonForeground : vscForeground}; - cursor: pointer; - - :disabled { - cursor: wait; - } -`; - export interface ToolbarOptions { hideUseCodebase?: boolean; hideImageUpload?: boolean; diff --git a/gui/src/components/mainInput/InputToolbar/EnterButton.tsx b/gui/src/components/mainInput/InputToolbar/EnterButton.tsx new file mode 100644 index 000000000..1eb5871d2 --- /dev/null +++ b/gui/src/components/mainInput/InputToolbar/EnterButton.tsx @@ -0,0 +1,29 @@ +import styled from "styled-components"; +import { + defaultBorderRadius, + lightGray, + vscButtonBackground, + vscButtonForeground, + vscForeground, +} from "../.."; +import { fontSize } from "../../../util"; + +export const EnterButton = styled.button<{ isPrimary?: boolean }>` + all: unset; + font-size: ${fontSize(-3)}; + padding: 2px 4px; + display: flex; + align-items: center; + background-color: ${(props) => + !props.disabled && props.isPrimary + ? vscButtonBackground + : lightGray + "33"}; + border-radius: ${defaultBorderRadius}; + color: ${(props) => + !props.disabled && props.isPrimary ? vscButtonForeground : vscForeground}; + cursor: pointer; + + :disabled { + cursor: wait; + } +`; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar.tsx index 2cac02cbb..dd91d4e66 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar.tsx @@ -1,10 +1,15 @@ -import { useContext } from "react"; +import { useContext, useEffect } from "react"; +import { useSelector } from "react-redux"; import styled from "styled-components"; import { AnimatedEllipsis } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; +import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; +import { callTool } from "../../../redux/thunks/callTool"; import { cancelStream } from "../../../redux/thunks/cancelStream"; +import { cancelTool } from "../../../redux/thunks/cancelTool"; import { getFontSize, getMetaKeyLabel } from "../../../util"; +import { EnterButton } from "../InputToolbar/EnterButton"; import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; const Container = styled.div` @@ -36,6 +41,31 @@ export function LumpToolbar() { const ttsActive = useAppSelector((state) => state.ui.ttsActive); const isStreaming = useAppSelector((state) => state.session.isStreaming); + const toolCallState = useSelector(selectCurrentToolCall); + + const handleKeyDown = (event: KeyboardEvent) => { + if (toolCallState?.status === "generated") { + const metaKey = event.metaKey || event.ctrlKey; + + if (metaKey && event.key === "Enter") { + event.preventDefault(); + event.stopPropagation(); + dispatch(callTool()); + } else if (metaKey && event.key === "Backspace") { + event.preventDefault(); + event.stopPropagation(); + dispatch(cancelTool()); + } + } + }; + + useEffect(() => { + document.addEventListener("keydown", handleKeyDown); + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }, [toolCallState]); + if (ttsActive) { return ( @@ -68,5 +98,31 @@ export function LumpToolbar() { ); } + if (toolCallState?.status === "generated") { + return ( + + + +
+ dispatch(cancelTool())} + data-testid="reject-tool-call-button" + > + {getMetaKeyLabel()} ⌫ Cancel + + dispatch(callTool())} + data-testid="accept-tool-call-button" + > + {getMetaKeyLabel()} ⏎ Continue + +
+
+ ); + } + return ; } diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 11017177b..ea5fcc983 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -37,7 +37,7 @@ import { newSession, selectIsInEditMode, selectIsSingleRangeEditOrInsertion, - updateToolCallOutput + updateToolCallOutput, } from "../../redux/slices/sessionSlice"; import { setDialogEntryOn, @@ -58,7 +58,6 @@ import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { ToolCallDiv } from "./ToolCallDiv"; -import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv"; import ToolOutput from "./ToolCallDiv/ToolOutput"; import { useAutoScroll } from "./useAutoScroll"; @@ -277,13 +276,13 @@ export function Chat() { useWebviewListener( "toolCallPartialOutput", async (data) => { - // Update tool call output in Redux store - dispatch( - updateToolCallOutput({ - toolCallId: data.toolCallId, - contextItems: data.contextItems, - }), - ); + // Update tool call output in Redux store + dispatch( + updateToolCallOutput({ + toolCallId: data.toolCallId, + contextItems: data.contextItems, + }), + ); }, [dispatch], ); @@ -410,8 +409,6 @@ export function Chat() { ))}
- {toolCallState?.status === "generated" && } - {isInEditMode && history.length === 0 && } {isInEditMode && history.length > 0 ? null : ( diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx deleted file mode 100644 index 3d770706b..000000000 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { useSelector } from "react-redux"; -import styled from "styled-components"; -import { - defaultBorderRadius, - lightGray, - vscButtonBackground, - vscButtonForeground, -} from "../../../components"; -import Spinner from "../../../components/gui/Spinner"; -import { useAppDispatch } from "../../../redux/hooks"; -import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; -import { callTool } from "../../../redux/thunks/callTool"; -import { cancelTool } from "../../../redux/thunks/cancelTool"; - -const ButtonContainer = styled.div` - display: flex; - gap: 8px; - margin-top: 12px; - margin: 8px; -`; - -const Button = styled.button` - padding: 5px; - border-radius: ${defaultBorderRadius}; - flex: 1; - - &:hover { - cursor: pointer; - opacity: 0.8; - } -`; - -const AcceptButton = styled(Button)` - color: ${vscButtonForeground}; - border: none; - background-color: ${vscButtonBackground}; - color: ${vscButtonForeground}; - - &:hover { - cursor: pointer; - } -`; - -const RejectButton = styled(Button)` - color: ${lightGray}; - border: 1px solid ${lightGray}; - background-color: transparent; -`; - -interface ToolCallButtonsProps {} - -export function ToolCallButtons(props: ToolCallButtonsProps) { - const dispatch = useAppDispatch(); - const toolCallState = useSelector(selectCurrentToolCall); - - if (!toolCallState) { - return null; - } - - return ( - <> - - {toolCallState.status === "generating" ? ( -
- Thinking... -
- ) : toolCallState.status === "generated" ? ( - <> - dispatch(cancelTool())} - data-testid="reject-tool-call-button" - > - Cancel - - dispatch(callTool())} - data-testid="accept-tool-call-button" - > - Continue - - - ) : toolCallState.status === "calling" ? ( -
- Loading... - -
- ) : null} -
- - ); -}