Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] 4abe1e9ca0 fix(app): insert dictation at the composer cursor
Use the live editor selection when a transcript arrives so dictated words go into the paragraph the user is editing.
2026-11-30 13:31:03 +00:00
3 changed files with 49 additions and 14 deletions
+5 -1
View File
@@ -1583,7 +1583,11 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
const autoSend = sendAfterTranscriptRef.current;
sendAfterTranscriptRef.current = false;
applyDictationTranscript(text, {
value: valueRef.current,
input: getComposerInputSnapshot(
textInputRef.current,
valueRef.current,
selectionRef.current,
),
defaultSendBehavior,
isAgentRunning,
onQueue,
+27 -1
View File
@@ -172,11 +172,37 @@ describe("dictation keyboard behavior", () => {
});
describe("dictation transcript behavior", () => {
it("inserts dictated words into the paragraph at the cursor", () => {
const value = "Intro: \n\nKeep this as the second paragraph.";
let draft = value;
let selection = { start: 7, end: 7 };
applyDictationTranscript("Spoken words.", {
input: { text: value, selection: { start: 7, end: 7 } },
defaultSendBehavior: "interrupt" as const,
isAgentRunning: false,
onQueue: undefined,
replaceText: (text, caret) => {
draft = text;
selection = caret ?? selection;
},
onSubmit: () => {
throw new Error("Insert must leave the message unsent");
},
attachments: [],
cwd: "/repo",
autoSend: false,
});
expect(draft).toBe("Intro: Spoken words.\n\nKeep this as the second paragraph.");
expect(selection).toEqual({ start: 20, end: 20 });
});
it("publishes an auto-sent transcript to the composer before submitting it", () => {
const actions: string[] = [];
applyDictationTranscript("spoken prompt", {
value: "typed context",
input: { text: "typed context", selection: { start: 13, end: 13 } },
defaultSendBehavior: "interrupt",
isAgentRunning: false,
onQueue: undefined,
+17 -12
View File
@@ -3,6 +3,8 @@ import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import type { ActiveTurnBehavior } from "@getpaseo/protocol/messages";
import type { MessagePayload, TextReplacement } from "@/composer/types";
import type { MessageInputKeyboardActionKind } from "@/keyboard/actions";
import { insertAtSelection } from "../insert-text";
import type { ComposerInputSnapshot } from "./input";
export type SendBehavior = ActiveTurnBehavior | "queue";
@@ -56,12 +58,12 @@ interface SendActionContext {
}
interface DictationTranscriptContext {
value: string;
input: ComposerInputSnapshot;
defaultSendBehavior: SendBehavior;
isAgentRunning: boolean;
onQueue: ((payload: MessagePayload) => void) | undefined;
onSubmit: (payload: MessagePayload) => void;
replaceText: (text: string) => void;
replaceText: (text: string, selection?: ComposerInputSnapshot["selection"]) => void;
attachments: MessagePayload["attachments"];
cwd: string;
autoSend: boolean;
@@ -69,24 +71,27 @@ interface DictationTranscriptContext {
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}`;
const selection = resolveRetainedSelection(ctx.input.selection, ctx.input.text.length);
const before = ctx.input.text.slice(0, selection.start);
const after = ctx.input.text.slice(selection.end);
const leadingSpace = /\S$/.test(before) ? " " : "";
const trailingSpace = /^[\p{L}\p{N}]/u.test(after) ? " " : "";
const next = insertAtSelection(
{ text: ctx.input.text, selection },
`${leadingSpace}${text}${trailingSpace}`,
);
if (!ctx.autoSend) {
ctx.replaceText(nextValue);
return;
}
ctx.replaceText(nextValue);
ctx.replaceText(next.text, next.selection);
if (!ctx.autoSend) return;
if (ctx.defaultSendBehavior === "queue" && ctx.isAgentRunning && ctx.onQueue) {
ctx.onQueue({ text: nextValue, attachments: ctx.attachments, cwd: ctx.cwd });
ctx.onQueue({ text: next.text, attachments: ctx.attachments, cwd: ctx.cwd });
ctx.replaceText("");
return;
}
ctx.onSubmit({
text: nextValue,
text: next.text,
attachments: ctx.attachments,
cwd: ctx.cwd,
forceSend: ctx.isAgentRunning || undefined,