Files
oh-my-pi/packages/coding-agent/test/custom-editor-keybindings.test.ts
T
can1357 652647770e feat(coding-agent): added app.live.toggle keybinding and map display reset to alt+l
- Add the `app.live.toggle` keybinding defaulted to `Ctrl+L` to start or stop live voice mode.
- Remap the default display-reset action (`app.display.reset`) from `Ctrl+L` to `Alt+L`.
- Update the live visualizer to listen for stop keys so the toggle chord terminates active sessions.
2026-07-31 00:20:04 +02:00

65 lines
2.1 KiB
TypeScript

import { beforeAll, describe, expect, it, vi } from "bun:test";
import { CustomEditor } from "@oh-my-pi/pi-coding-agent/modes/components/custom-editor";
import { getEditorTheme, initTheme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
describe("CustomEditor keybindings", () => {
beforeAll(async () => {
await initTheme();
});
it("routes the configured retry chord through handleInput", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
editor.setActionKeys("app.retry", ["alt+shift+r"]);
editor.onRetry = onRetry;
editor.handleInput("\x1bR");
expect(onRetry).toHaveBeenCalledTimes(1);
});
it("lets custom handlers keep precedence over the default retry chord", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
const customHandler = vi.fn();
editor.onRetry = onRetry;
editor.setCustomKeyHandler("alt+r", customHandler);
editor.handleInput("\x1br");
expect(customHandler).toHaveBeenCalledTimes(1);
expect(onRetry).not.toHaveBeenCalled();
});
it("lets copy-prompt remaps keep precedence over the default retry chord", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
const onCopyPrompt = vi.fn();
editor.onRetry = onRetry;
editor.onCopyPrompt = onCopyPrompt;
editor.setActionKeys("app.clipboard.copyPrompt", ["alt+r"]);
editor.handleInput("\x1br");
expect(onCopyPrompt).toHaveBeenCalledTimes(1);
expect(onRetry).not.toHaveBeenCalled();
});
it("routes Ctrl+L to a live-toggle custom handler and Alt+L to display reset by default", () => {
const editor = new CustomEditor(getEditorTheme());
const onDisplayReset = vi.fn();
const onLiveToggle = vi.fn();
editor.onDisplayReset = onDisplayReset;
editor.setCustomKeyHandler("ctrl+l", onLiveToggle);
editor.handleInput("\x0c"); // Ctrl+L
expect(onLiveToggle).toHaveBeenCalledTimes(1);
expect(onDisplayReset).not.toHaveBeenCalled();
editor.handleInput("\x1bl"); // Alt+L
expect(onDisplayReset).toHaveBeenCalledTimes(1);
expect(onLiveToggle).toHaveBeenCalledTimes(1);
});
});