fix(app): preserve dictation text during submit (#2745)
Dictation auto-send bypassed the controlled composer update, so preserved draft surfaces could lock while showing an empty prompt. Publish the transcript before invoking the existing submit lifecycle so pending and failed submissions retain the user's spoken input.
This commit is contained in:
@@ -46,6 +46,44 @@ interface SendActionContext {
|
||||
handleQueueMessage: () => void;
|
||||
}
|
||||
|
||||
interface DictationTranscriptContext {
|
||||
value: string;
|
||||
defaultSendBehavior: SendBehavior;
|
||||
isAgentRunning: boolean;
|
||||
onQueue: ((payload: MessagePayload) => void) | undefined;
|
||||
onSubmit: (payload: MessagePayload) => void;
|
||||
onChangeText: (text: string) => void;
|
||||
attachments: MessagePayload["attachments"];
|
||||
cwd: string;
|
||||
autoSend: boolean;
|
||||
}
|
||||
|
||||
export function applyDictationTranscript(text: string, ctx: DictationTranscriptContext): void {
|
||||
if (!text) return;
|
||||
const shouldPad = ctx.value.length > 0 && !/\s$/.test(ctx.value);
|
||||
const nextValue = `${ctx.value}${shouldPad ? " " : ""}${text}`;
|
||||
|
||||
if (!ctx.autoSend) {
|
||||
ctx.onChangeText(nextValue);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.onChangeText(nextValue);
|
||||
|
||||
if (ctx.defaultSendBehavior === "queue" && ctx.isAgentRunning && ctx.onQueue) {
|
||||
ctx.onQueue({ text: nextValue, attachments: ctx.attachments, cwd: ctx.cwd });
|
||||
ctx.onChangeText("");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.onSubmit({
|
||||
text: nextValue,
|
||||
attachments: ctx.attachments,
|
||||
cwd: ctx.cwd,
|
||||
forceSend: ctx.isAgentRunning || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
interface MessageInputKeyboardActions {
|
||||
focusInput: () => void;
|
||||
isDictationRecording: () => boolean;
|
||||
|
||||
Reference in New Issue
Block a user