fix(webui): disarm queued prompt for voice shortcut
This commit is contained in:
@@ -1304,6 +1304,7 @@ export function ThreadComposer({
|
||||
function onKeyDown(event: KeyboardEvent): void {
|
||||
if (!isVoiceShortcutDown(event) || event.repeat || voiceShortcutDownRef.current) return;
|
||||
event.preventDefault();
|
||||
secondEnterPromptIdRef.current = null;
|
||||
voiceShortcutDownRef.current = true;
|
||||
voiceRecorder.beginShortcutHold();
|
||||
}
|
||||
|
||||
@@ -1581,9 +1581,41 @@ describe("ThreadComposer", () => {
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(onSend).toHaveBeenCalledWith("send this guidance now");
|
||||
expect(onSend).toHaveBeenCalledTimes(1);
|
||||
expect(screen.queryByText("send this guidance now")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("disarms the second Enter shortcut when keyboard voice recording starts", async () => {
|
||||
mockVoiceRecorder();
|
||||
const onSend = vi.fn();
|
||||
const onTranscribeAudio = vi.fn(async () => "voice guidance");
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={onSend}
|
||||
onStop={vi.fn()}
|
||||
onTranscribeAudio={onTranscribeAudio}
|
||||
isStreaming
|
||||
placeholder="Type your message..."
|
||||
/>,
|
||||
);
|
||||
|
||||
const input = screen.getByLabelText("Message input");
|
||||
fireEvent.change(input, { target: { value: "keep this queued" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
fireEvent.keyDown(window, { code: "KeyD", ctrlKey: true, key: "D", shiftKey: true });
|
||||
|
||||
expect(await screen.findByLabelText("Recording 0:00")).toBeInTheDocument();
|
||||
expect(input).toHaveFocus();
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(onSend).not.toHaveBeenCalled();
|
||||
expect(screen.getByText("keep this queued")).toBeInTheDocument();
|
||||
|
||||
await waitForVoiceCapture();
|
||||
fireEvent.keyUp(window, { code: "KeyD", ctrlKey: true, key: "D", shiftKey: true });
|
||||
await waitFor(() => expect(onTranscribeAudio).toHaveBeenCalled());
|
||||
});
|
||||
|
||||
it("disarms the second Enter shortcut after stopping the active response", () => {
|
||||
const onSend = vi.fn();
|
||||
const onStop = vi.fn();
|
||||
@@ -1669,6 +1701,7 @@ describe("ThreadComposer", () => {
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(onSend).toHaveBeenCalledWith("guide this one now");
|
||||
expect(onSend).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByText("older guidance")).toBeInTheDocument();
|
||||
expect(screen.queryByText("guide this one now")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -2021,6 +2054,19 @@ describe("ThreadComposer", () => {
|
||||
expect(screen.queryByText("remember this edited follow-up")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
rerender(
|
||||
<ThreadComposer
|
||||
onSend={onSend}
|
||||
onStop={vi.fn()}
|
||||
isStreaming
|
||||
pendingQueueKey="chat-a"
|
||||
placeholder="Type your message..."
|
||||
/>,
|
||||
);
|
||||
expect(await screen.findByText("remember this edited follow-up")).toBeInTheDocument();
|
||||
fireEvent.keyDown(screen.getByLabelText("Message input"), { key: "Enter" });
|
||||
expect(onSend).not.toHaveBeenCalled();
|
||||
|
||||
unmount();
|
||||
const remount = render(
|
||||
<ThreadComposer
|
||||
|
||||
Reference in New Issue
Block a user