diff --git a/.changeset/eight-jokes-punch.md b/.changeset/eight-jokes-punch.md new file mode 100644 index 0000000000..9d3b2e4d2b --- /dev/null +++ b/.changeset/eight-jokes-punch.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Do not clear the input value when changing modes without sending a message diff --git a/proto/state.proto b/proto/state.proto index 7729a72da7..894567c2c0 100644 --- a/proto/state.proto +++ b/proto/state.proto @@ -14,7 +14,7 @@ service StateService { rpc subscribeToState(EmptyRequest) returns (stream State); rpc toggleFavoriteModel(StringRequest) returns (Empty); rpc resetState(ResetStateRequest) returns (Empty); - rpc togglePlanActMode(TogglePlanActModeRequest) returns (Empty); + rpc togglePlanActMode(TogglePlanActModeRequest) returns (Boolean); rpc updateAutoApprovalSettings(AutoApprovalSettingsRequest) returns (Empty); rpc updateSettings(UpdateSettingsRequest) returns (Empty); } diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index b7fa62a307..25b24a6bb5 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -268,7 +268,7 @@ export class Controller { telemetryService.updateTelemetryState(isOptedIn) } - async togglePlanActModeWithChatSettings(chatSettings: ChatSettings, chatContent?: ChatContent) { + async togglePlanActModeWithChatSettings(chatSettings: ChatSettings, chatContent?: ChatContent): Promise { const didSwitchToActMode = chatSettings.mode === "act" // Capture mode switch telemetry | Capture regardless of if we know the taskId @@ -454,10 +454,15 @@ export class Controller { chatContent?.images || [], chatContent?.files || [], ) + + return true } else { this.cancelTask() + return false } } + + return false } async cancelTask() { diff --git a/src/core/controller/state/togglePlanActMode.ts b/src/core/controller/state/togglePlanActMode.ts index 7d8cc4b85f..602cd78eee 100644 --- a/src/core/controller/state/togglePlanActMode.ts +++ b/src/core/controller/state/togglePlanActMode.ts @@ -1,5 +1,5 @@ import { Controller } from ".." -import { Empty } from "../../../shared/proto/common" +import { Boolean } from "../../../shared/proto/common" import { TogglePlanActModeRequest } from "../../../shared/proto/state" import { convertProtoChatContentToChatContent, @@ -12,7 +12,7 @@ import { * @param request The request containing the chat settings and optional chat content * @returns An empty response */ -export async function togglePlanActMode(controller: Controller, request: TogglePlanActModeRequest): Promise { +export async function togglePlanActMode(controller: Controller, request: TogglePlanActModeRequest): Promise { try { if (!request.chatSettings) { throw new Error("Chat settings are required") @@ -22,9 +22,11 @@ export async function togglePlanActMode(controller: Controller, request: ToggleP const chatContent = request.chatContent ? convertProtoChatContentToChatContent(request.chatContent) : undefined // Call the existing controller implementation - await controller.togglePlanActModeWithChatSettings(chatSettings, chatContent) + const sentMessage = await controller.togglePlanActModeWithChatSettings(chatSettings, chatContent) - return Empty.create() + return Boolean.create({ + value: sentMessage, + }) } catch (error) { console.error("Failed to toggle Plan/Act mode:", error) throw error diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index 230912a288..4aec7ed7b5 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -82,7 +82,6 @@ interface ChatTextAreaProps { shouldDisableFilesAndImages: boolean onHeightChange?: (height: number) => void onFocusChange?: (isFocused: boolean) => void - isTaskView: boolean } interface GitCommit { @@ -270,7 +269,6 @@ const ChatTextArea = forwardRef( shouldDisableFilesAndImages, onHeightChange, onFocusChange, - isTaskView, }, ref, ) => { @@ -1000,9 +998,9 @@ const ChatTextArea = forwardRef( submitApiConfig() changeModeDelay = 250 // necessary to let the api config update (we send message and wait for it to be saved) FIXME: this is a hack and we ideally should check for api config changes, then wait for it to be saved, before switching modes } - setTimeout(() => { + setTimeout(async () => { const newMode = chatSettings.mode === "plan" ? PlanActMode.ACT : PlanActMode.PLAN - StateServiceClient.togglePlanActMode( + const response = await StateServiceClient.togglePlanActMode( TogglePlanActModeRequest.create({ chatSettings: { mode: newMode, @@ -1018,7 +1016,7 @@ const ChatTextArea = forwardRef( ) // Focus the textarea after mode toggle with slight delay setTimeout(() => { - if (isTaskView) { + if (response.value) { setInputValue("") } textAreaRef.current?.focus() diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 3398113e90..dfbef9c698 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -1265,7 +1265,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie scrollToBottomAuto() } }} - isTaskView={!!task} /> )