Files
openidea/src/features/settings/presentation/presentation.ts
T
l0ng-ai c8a91e5b0f feat(appearance): Presentation Assistant (#4026)
While on, each action the user runs shows its name and shortcut in a popup, for screencasts and demos. Toggled from View › Appearance › Presentation Assistant; Settings › Appearance › Presentation Assistant sets the popup size, duration, position and whether to also show the other platform's shortcut (macOS ⇄ Windows/Linux). Hidden actions are not shown.

Closes #3949
2026-11-17 23:01:12 +08:00

44 lines
1.8 KiB
TypeScript

/**
* Presentation Assistant: what to show for an action the user ran, its name and shortcut, and
* optionally the shortcut in the other platform's keymap (macOS ⇄ Windows/Linux).
*/
import { getAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import {
formatBinding,
isMacHost,
isMouseBinding,
presetBindings,
primaryKeyBinding,
PRESETS,
useKeymap,
} from "@/platform/keymap";
export interface PresentedAction {
title: string;
shortcut?: string;
/** The shortcut in the other platform's keymap, with that platform's name. */
alternate?: { keymap: string; shortcut: string };
}
/** The same keymap family on the other platform (`intellij-macos` ⇄ `intellij-windows`). */
export function alternatePreset(preset: string, mac: boolean): string {
const swapped = mac ? preset.replace(/-macos$/, "-windows") : preset.replace(/-windows$/, "-macos");
if (swapped !== preset && swapped in PRESETS) return swapped;
return mac ? "intellij-windows" : "intellij-macos";
}
export function presentAction(id: string, alternateKeymap: boolean, mac = isMacHost()): PresentedAction | null {
const action = getAction(id);
// Hidden actions are internal steps (accepting a completion, focusing the editor), not commands.
if (!action || action.hidden) return null;
const title = action.verbatim ? action.title : tx(action.title);
const binding = primaryKeyBinding(id);
const presented: PresentedAction = { title, shortcut: binding ? formatBinding(binding, mac) : undefined };
if (alternateKeymap) {
const other = presetBindings(alternatePreset(useKeymap.getState().preset, mac), id).find((b) => !isMouseBinding(b));
if (other) presented.alternate = { keymap: mac ? "Windows/Linux" : "macOS", shortcut: formatBinding(other, !mac) };
}
return presented;
}