mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
fix(webui): disarm queued prompt for voice shortcut
This commit is contained in:
parent
04328f8129
commit
47d498bab0
@ -1304,6 +1304,7 @@ export function ThreadComposer({
|
|||||||
function onKeyDown(event: KeyboardEvent): void {
|
function onKeyDown(event: KeyboardEvent): void {
|
||||||
if (!isVoiceShortcutDown(event) || event.repeat || voiceShortcutDownRef.current) return;
|
if (!isVoiceShortcutDown(event) || event.repeat || voiceShortcutDownRef.current) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
secondEnterPromptIdRef.current = null;
|
||||||
voiceShortcutDownRef.current = true;
|
voiceShortcutDownRef.current = true;
|
||||||
voiceRecorder.beginShortcutHold();
|
voiceRecorder.beginShortcutHold();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1581,9 +1581,41 @@ describe("ThreadComposer", () => {
|
|||||||
fireEvent.keyDown(input, { key: "Enter" });
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
|
||||||
expect(onSend).toHaveBeenCalledWith("send this guidance now");
|
expect(onSend).toHaveBeenCalledWith("send this guidance now");
|
||||||
|
expect(onSend).toHaveBeenCalledTimes(1);
|
||||||
expect(screen.queryByText("send this guidance now")).not.toBeInTheDocument();
|
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", () => {
|
it("disarms the second Enter shortcut after stopping the active response", () => {
|
||||||
const onSend = vi.fn();
|
const onSend = vi.fn();
|
||||||
const onStop = vi.fn();
|
const onStop = vi.fn();
|
||||||
@ -1669,6 +1701,7 @@ describe("ThreadComposer", () => {
|
|||||||
fireEvent.keyDown(input, { key: "Enter" });
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
|
||||||
expect(onSend).toHaveBeenCalledWith("guide this one now");
|
expect(onSend).toHaveBeenCalledWith("guide this one now");
|
||||||
|
expect(onSend).toHaveBeenCalledTimes(1);
|
||||||
expect(screen.getByText("older guidance")).toBeInTheDocument();
|
expect(screen.getByText("older guidance")).toBeInTheDocument();
|
||||||
expect(screen.queryByText("guide this one now")).not.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();
|
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();
|
unmount();
|
||||||
const remount = render(
|
const remount = render(
|
||||||
<ThreadComposer
|
<ThreadComposer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user