fix: Clear the input only after creating a message (#4288)

* Return if the message was sent when toggling plan act mode to properly clear the input

* Add changeset

* Use a common value instead of a unique response
This commit is contained in:
Tomás Barreiro
2025-06-19 14:01:22 -06:00
committed by GitHub
parent 8aa6935cbb
commit 288f1bf7f8
6 changed files with 21 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Do not clear the input value when changing modes without sending a message
+1 -1
View File
@@ -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);
}
+6 -1
View File
@@ -268,7 +268,7 @@ export class Controller {
telemetryService.updateTelemetryState(isOptedIn)
}
async togglePlanActModeWithChatSettings(chatSettings: ChatSettings, chatContent?: ChatContent) {
async togglePlanActModeWithChatSettings(chatSettings: ChatSettings, chatContent?: ChatContent): Promise<boolean> {
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() {
@@ -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<Empty> {
export async function togglePlanActMode(controller: Controller, request: TogglePlanActModeRequest): Promise<Boolean> {
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
@@ -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<HTMLTextAreaElement, ChatTextAreaProps>(
shouldDisableFilesAndImages,
onHeightChange,
onFocusChange,
isTaskView,
},
ref,
) => {
@@ -1000,9 +998,9 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
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<HTMLTextAreaElement, ChatTextAreaProps>(
)
// Focus the textarea after mode toggle with slight delay
setTimeout(() => {
if (isTaskView) {
if (response.value) {
setInputValue("")
}
textAreaRef.current?.focus()
@@ -1265,7 +1265,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
scrollToBottomAuto()
}
}}
isTaskView={!!task}
/>
</div>
)