Files
backnotprop__plannotator/packages/ui/utils/wideMode.ts
Michael Ramos 1bf90a2357 feat(editor): focus-mode shortcut to toggle both sidebars (#1279)
* feat(editor): focus-mode shortcut to toggle both sidebars (#1276)

Keyboard-first reviewers had to reach for the mouse to collapse the
Contents sidebar and the right-hand panel every time they wanted to read
a document. Bind that to one key.

Mod+. now toggles the existing `focus` view mode from the keyboard, on
both the plan review and annotate surfaces. The first press remembers
whatever was open and closes both panels; the next press restores that
exact arrangement, so a session with only one panel open comes back the
same way. Any manual open (a sidebar tab, the annotation panel, the
agent terminal) already exits the view mode and clears the memory, so
the shortcut cannot leave the layout stuck.

The binding was picked after auditing every plan-review and annotate
binding: Mod+B / Mod+Shift+B are the sidebar toggles, Mod+S, Mod+P,
Mod+Enter, Mod+C and Mod+Z are taken, and code review already uses
Mod+. for its own "collapse the chrome" toggle. It is unshifted on every
keyboard layout and claimed by no browser or OS default.

The dispatcher gate is shared with the annotate sidebar shortcuts, so
the key is inert while a dialog, an overlay, a submission, or a text
field owns the keystroke. HTML surfaces are excluded because they own
their own persisted chrome and never render the Focus control.

* fix(editor): keep focus-mode exit reachable on HTML surfaces; note the HTML caveat in help
2026-08-12 11:54:31 -07:00

69 lines
2.0 KiB
TypeScript

import type { SidebarTab } from '@plannotator/ui/hooks/useSidebar';
import type { WideModeType } from '@plannotator/ui/types';
export type { WideModeType } from '@plannotator/ui/types';
export type WideModeLayoutSnapshot = {
sidebarIsOpen: boolean;
sidebarTab: SidebarTab;
panelOpen: boolean;
};
export type WideModeExitOptions = {
restore?: boolean;
sidebarTab?: SidebarTab;
panelOpen?: boolean;
};
export type WideModeExitLayout = {
sidebarOpen: boolean;
sidebarTab: SidebarTab | null;
panelOpen?: boolean;
};
export function canUseAnnotateWideMode(options: {
archiveMode: boolean;
isPlanDiffActive: boolean;
}): boolean {
return !options.archiveMode && !options.isPlanDiffActive;
}
/** What the focus-mode keyboard shortcut should do on this press. */
export type FocusShortcutAction = 'enter-focus' | 'exit' | 'none';
/**
* Decide the next step for the focus-mode keyboard shortcut.
*
* The shortcut is a single "hide the chrome / give it back" toggle, so ANY
* active panel-hiding view mode restores the remembered layout — including
* `wide`, which the toolbar control would instead swap for `focus`. A press
* that could only re-hide already-hidden panels would look like a dead key.
*/
export function resolveFocusShortcutAction(state: {
canUseWideMode: boolean;
wideModeType: WideModeType | null;
}): FocusShortcutAction {
if (state.wideModeType !== null) return 'exit';
return state.canUseWideMode ? 'enter-focus' : 'none';
}
export function resolveWideModeExitLayout(
snapshot: WideModeLayoutSnapshot | null,
options?: WideModeExitOptions,
): WideModeExitLayout {
const restore = options?.restore !== false;
if (options?.sidebarTab) {
return {
sidebarOpen: true,
sidebarTab: options.sidebarTab,
panelOpen: options.panelOpen,
};
}
return {
sidebarOpen: restore ? (snapshot?.sidebarIsOpen ?? false) : false,
sidebarTab: restore && snapshot?.sidebarIsOpen ? snapshot.sidebarTab : null,
panelOpen: options?.panelOpen ?? (restore ? (snapshot?.panelOpen ?? false) : undefined),
};
}