mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-30 06:32:24 +00:00
- Implement command palette (⌘K) using cmdk and Radix Dialog with a global action registry. - Add a keyboard shortcut system with a capture-phase hotkey manager and scope stack. - Integrate seed navigation actions for Home, Chat, Intelligence, Skills, and Settings. - Improve chat UX with a `useStickToBottom` hook for auto-scroll and fixed hydration errors. - Refactor command UI to display shortcuts inline and remove the redundant help overlay. - Fix Vite HMR connection issues within the Tauri/CEF environment. Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { expect } from 'vitest';
|
|
|
|
export interface PressKeyOptions {
|
|
key: string;
|
|
mod?: boolean;
|
|
shift?: boolean;
|
|
alt?: boolean;
|
|
ctrl?: boolean;
|
|
target?: EventTarget;
|
|
}
|
|
|
|
export function pressKey(opts: PressKeyOptions): KeyboardEvent {
|
|
const mac = navigator.platform.toLowerCase().includes('mac');
|
|
const modPair = opts.mod ? (mac ? { metaKey: true } : { ctrlKey: true }) : {};
|
|
const target = opts.target ?? window;
|
|
const event = new KeyboardEvent('keydown', {
|
|
key: opts.key,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
shiftKey: !!opts.shift,
|
|
altKey: !!opts.alt,
|
|
ctrlKey: !!opts.ctrl,
|
|
...modPair,
|
|
});
|
|
target.dispatchEvent(event);
|
|
return event;
|
|
}
|
|
|
|
export function __metaAssertPressKeyReachesCaptureListener(): void {
|
|
let reached = false;
|
|
const listener = (_e: KeyboardEvent) => {
|
|
reached = true;
|
|
};
|
|
window.addEventListener('keydown', listener, { capture: true });
|
|
pressKey({ key: 'z' });
|
|
window.removeEventListener('keydown', listener, { capture: true });
|
|
expect(reached).toBe(true);
|
|
}
|