Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: stop OpenWorld movement input while a dialog is open or a field is focused (#4731)

[._.]/ Adam Eivyf9d6af931dbc
diff --git a/client/src/hooks/useKeyboardControls.js b/client/src/hooks/useKeyboardControls.js
index a181a83628..ad2f91515e 100644
--- a/client/src/hooks/useKeyboardControls.js
+++ b/client/src/hooks/useKeyboardControls.js
@@ -1,9 +1,19 @@
import { useRef, useEffect, useCallback } from 'react';
+import { isEditableTarget } from './useKeyboardShortcuts.js';
+
+// Movement input is only ever meant for the world behind the UI, so a keystroke aimed at
+// a form field or at an open dialog must not reach the rig: typing "w" in the fast-travel
+// search would otherwise walk the avatar, and Space inside the settings drawer would jump
+// it (Tab likewise has to move focus in those contexts, not flip exploration mode).
+// Note this is a keyDOWN-only gate — keyup always clears, or a key held when a dialog
+// opens would stay stuck down forever.
+const ignoresMovement = (e) => isEditableTarget(e.target) || Boolean(document.querySelector('[aria-modal="true"]'));
export default function useKeyboardControls(onToggleMode) {
const keysRef = useRef(new Set());
const handleKeyDown = useCallback((e) => {
+ if (ignoresMovement(e)) return;
if (e.key === 'Tab') {
e.preventDefault();
onToggleMode?.();
diff --git a/client/src/hooks/useKeyboardControls.test.jsx b/client/src/hooks/useKeyboardControls.test.jsx
new file mode 100644
index 0000000000..c74cd0f6b5
--- /dev/null
+++ b/client/src/hooks/useKeyboardControls.test.jsx
@@ -0,0 +1,95 @@
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { render, fireEvent, cleanup } from '@testing-library/react';
+import useKeyboardControls from './useKeyboardControls';
+
+// The hook hands back the live held-key Set the OpenWorld rig reads every frame, so the
+// assertions here are about what does and does not end up in that Set.
+const keys = { current: null };
+
+function Probe({ onToggleMode }) {
+ keys.current = useKeyboardControls(onToggleMode);
+ return <input aria-label="search" />;
+}
+
+function openDialog() {
+ const dialog = document.createElement('div');
+ dialog.setAttribute('aria-modal', 'true');
+ document.body.appendChild(dialog);
+ return () => dialog.remove();
+}
+
+afterEach(cleanup);
+
+describe('useKeyboardControls', () => {
+ it('records a held movement key and clears it on release', () => {
+ render(<Probe />);
+
+ fireEvent.keyDown(document.body, { key: 'W' });
+ expect(keys.current.current.has('w')).toBe(true);
+
+ fireEvent.keyUp(document.body, { key: 'W' });
+ expect(keys.current.current.has('w')).toBe(false);
+ });
+
+ it('clears the released key even for a Space claimed by a capture-phase listener', () => {
+ // PlayerController claims the Space keydown (so the voice hotkey never sees it) and
+ // adds ' ' itself, then relies on THIS listener to clear it — it binds no keyup.
+ render(<Probe />);
+ keys.current.current.add(' ');
+
+ fireEvent.keyUp(document.body, { key: ' ' });
+
+ expect(keys.current.current.has(' ')).toBe(false);
+ });
+
+ it('ignores keys typed into a form field', () => {
+ const { getByLabelText } = render(<Probe />);
+
+ fireEvent.keyDown(getByLabelText('search'), { key: 'w' });
+
+ expect(keys.current.current.has('w')).toBe(false);
+ });
+
+ it('ignores movement while a dialog is open, so the rig stays put behind it', () => {
+ render(<Probe />);
+ const close = openDialog();
+
+ fireEvent.keyDown(document.body, { key: ' ' });
+ fireEvent.keyDown(document.body, { key: 'w' });
+
+ expect(keys.current.current.has(' ')).toBe(false);
+ expect(keys.current.current.has('w')).toBe(false);
+ close();
+ });
+
+ it('toggles exploration mode on Tab', () => {
+ const onToggleMode = vi.fn();
+ render(<Probe onToggleMode={onToggleMode} />);
+
+ fireEvent.keyDown(document.body, { key: 'Tab' });
+
+ expect(onToggleMode).toHaveBeenCalledTimes(1);
+ expect(keys.current.current.has('tab')).toBe(false);
+ });
+
+ it('leaves Tab alone in a form field and behind a dialog, where it must move focus', () => {
+ const onToggleMode = vi.fn();
+ const { getByLabelText } = render(<Probe onToggleMode={onToggleMode} />);
+
+ fireEvent.keyDown(getByLabelText('search'), { key: 'Tab' });
+ const close = openDialog();
+ fireEvent.keyDown(document.body, { key: 'Tab' });
+ close();
+
+ expect(onToggleMode).not.toHaveBeenCalled();
+ });
+
+ it('drops every held key when the window loses focus', () => {
+ render(<Probe />);
+ fireEvent.keyDown(document.body, { key: 'w' });
+
+ fireEvent.blur(window);
+
+ expect(keys.current.current.size).toBe(0);
+ });
+});
diff --git a/client/src/pages/OpenWorld.transport.test.jsx b/client/src/pages/OpenWorld.transport.test.jsx
index c0f1af4f0a..eec891bdcc 100644
--- a/client/src/pages/OpenWorld.transport.test.jsx
+++ b/client/src/pages/OpenWorld.transport.test.jsx
@@ -1,13 +1,21 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
-import { render, fireEvent, act } from '@testing-library/react';
+import { render, screen, fireEvent, act } from '@testing-library/react';
import { MemoryRouter, Routes, Route } from 'react-router';
import { installVoiceHotkeySpy } from '../test/voiceHotkeySpy';
// Same stubbing strategy as OpenWorld.fastTravel.test.jsx: the 3D scene and the HUD are
// replaced with inert divs so the page's keyboard WIRING can be exercised in jsdom.
vi.mock('../components/openworld/OpenWorldScene', () => ({ default: () => <div data-testid="scene" /> }));
-vi.mock('../components/openworld/OpenWorldHud', () => ({ default: () => null }));
-vi.mock('../components/openworld/OpenWorldPhotoOverlay', () => ({ default: () => null }));
+vi.mock('../components/openworld/OpenWorldHud', () => ({
+ default: ({ onEnterPhotoMode }) => (
+ <button type="button" onClick={onEnterPhotoMode}>hud-photo</button>
+ ),
+}));
+// Photo mode has no other observable surface once the overlay is stubbed, so the stub
+// records the props the page drives from its keyboard shortcuts.
+vi.mock('../components/openworld/OpenWorldPhotoOverlay', () => ({
+ default: (props) => { photoProps.current = props; return null; },
+}));
vi.mock('../components/openworld/OpenWorldPlaybackOverlay', () => ({ default: () => null }));
vi.mock('../components/openworld/OpenWorldSettingsDrawer', () => ({ default: () => null }));
@@ -22,6 +30,7 @@ vi.mock('../hooks/useOpenWorldData', () => ({
// The playback hook is the surface under test: the page binds its transport keys only
// while `active`, and the spies below record what each key reached.
+const photoProps = vi.hoisted(() => ({ current: null }));
const playback = vi.hoisted(() => ({
active: true, currentFrame: null, snapshots: [], frameIndex: 0, stats: null,
playing: false, speed: 1, loading: false, error: null,
@@ -129,3 +138,56 @@ describe('OpenWorld playback transport keys', () => {
expect(voiceHotkey()).toHaveBeenCalledTimes(1);
});
});
+
+describe('OpenWorld photo mode shortcuts', () => {
+ const voiceHotkey = installVoiceHotkeySpy();
+
+ beforeEach(() => {
+ playback.active = false;
+ photoProps.current = null;
+ localStorage.clear();
+ });
+
+ const enterPhotoMode = () => {
+ const rendered = renderPage();
+ fireEvent.click(screen.getByText('hud-photo'));
+ return rendered;
+ };
+
+ it('cycles the framing preset and toggles depth of field', () => {
+ enterPhotoMode();
+ expect(photoProps.current.active).toBe(true);
+ const first = photoProps.current.presetId;
+ expect(photoProps.current.dofEnabled).toBe(true);
+
+ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowRight' }); });
+ expect(photoProps.current.presetId).not.toBe(first);
+
+ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowLeft' }); });
+ expect(photoProps.current.presetId).toBe(first);
+
+ act(() => { fireEvent.keyDown(document.body, { key: 'd' }); });
+ expect(photoProps.current.dofEnabled).toBe(false);
+ });
+
+ it('exits on Escape', () => {
+ enterPhotoMode();
+
+ act(() => { fireEvent.keyDown(document.body, { key: 'Escape' }); });
+
+ expect(photoProps.current.active).toBe(false);
+ });
+
+ it('leaves its keys for an open dialog, and does not claim them from the app', () => {
+ const { container } = enterPhotoMode();
+ const dialog = document.createElement('div');
+ dialog.setAttribute('aria-modal', 'true');
+ container.appendChild(dialog);
+
+ act(() => { fireEvent.keyDown(document.body, { key: 'Escape' }); });
+
+ expect(photoProps.current.active).toBe(true);
+ // Bubble-phase shortcuts, not a capture-phase claim: the app still sees the key.
+ expect(voiceHotkey()).toHaveBeenCalledTimes(1);
+ });
+});