mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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
This commit is contained in:
@@ -783,6 +783,35 @@ pub struct AppearanceSettings {
|
||||
pub main_toolbar: Option<MainToolbarSettings>,
|
||||
/// Appearance › Background Image: an image shown through the IDE window.
|
||||
pub background_image: BackgroundImageSettings,
|
||||
/// Appearance › Presentation Assistant: the name and shortcut of each action run.
|
||||
pub presentation_assistant: PresentationAssistantSettings,
|
||||
}
|
||||
|
||||
/// Appearance › Presentation Assistant: shows the name and shortcut of each action the user runs.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct PresentationAssistantSettings {
|
||||
pub enabled: bool,
|
||||
/// `small` | `medium` | `large`.
|
||||
pub size: String,
|
||||
/// How long each popup stays, in seconds.
|
||||
pub duration_seconds: u32,
|
||||
/// `top-left`, `top`, `top-right`, `bottom-left`, `bottom` or `bottom-right` of the window.
|
||||
pub position: String,
|
||||
/// Also show the shortcut of the other platform's keymap (macOS ⇄ Windows/Linux).
|
||||
pub alternate_keymap: bool,
|
||||
}
|
||||
|
||||
impl Default for PresentationAssistantSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
size: "medium".into(),
|
||||
duration_seconds: 4,
|
||||
position: "bottom".into(),
|
||||
alternate_keymap: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Appearance › Background Image. An empty `path` shows no image.
|
||||
@@ -875,6 +904,7 @@ impl Default for AppearanceSettings {
|
||||
status_bar_widgets: BTreeMap::new(),
|
||||
main_toolbar: None,
|
||||
background_image: BackgroundImageSettings::default(),
|
||||
presentation_assistant: PresentationAssistantSettings::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +396,7 @@ pub fn spec(os: Os) -> Vec<Entry> {
|
||||
act("editor.toggleZen", "Enter Distraction Free Mode"),
|
||||
act("window.toggleFullScreen", "Toggle Full Screen"),
|
||||
toggle("view.toggleCompactMode", "Compact Mode"),
|
||||
toggle("view.togglePresentationAssistant", "Presentation Assistant"),
|
||||
SEP,
|
||||
act("view.zoomIn", "Zoom In IDE"),
|
||||
act("view.zoomOut", "Zoom Out IDE"),
|
||||
|
||||
@@ -2812,6 +2812,8 @@ export type AppearanceSettings_Deserialize = {
|
||||
mainToolbar?: MainToolbarSettings | null,
|
||||
/** Appearance › Background Image: an image shown through the IDE window. */
|
||||
backgroundImage?: BackgroundImageSettings,
|
||||
/** Appearance › Presentation Assistant: the name and shortcut of each action run. */
|
||||
presentationAssistant?: PresentationAssistantSettings,
|
||||
};
|
||||
|
||||
export type AppearanceSettings_Serialize = {
|
||||
@@ -2881,6 +2883,8 @@ export type AppearanceSettings_Serialize = {
|
||||
mainToolbar: MainToolbarSettings | null,
|
||||
/** Appearance › Background Image: an image shown through the IDE window. */
|
||||
backgroundImage: BackgroundImageSettings,
|
||||
/** Appearance › Presentation Assistant: the name and shortcut of each action run. */
|
||||
presentationAssistant: PresentationAssistantSettings,
|
||||
};
|
||||
|
||||
export type ApplyOutcome = {
|
||||
@@ -9213,6 +9217,19 @@ export type PreparedRequest = {
|
||||
body: string | null,
|
||||
};
|
||||
|
||||
/** Appearance › Presentation Assistant: shows the name and shortcut of each action the user runs. */
|
||||
export type PresentationAssistantSettings = {
|
||||
enabled?: boolean,
|
||||
/** `small` | `medium` | `large`. */
|
||||
size?: string,
|
||||
/** How long each popup stays, in seconds. */
|
||||
durationSeconds?: number,
|
||||
/** `top-left`, `top`, `top-right`, `bottom-left`, `bottom` or `bottom-right` of the window. */
|
||||
position?: string,
|
||||
/** Also show the shortcut of the other platform's keymap (macOS ⇄ Windows/Linux). */
|
||||
alternateKeymap?: boolean,
|
||||
};
|
||||
|
||||
export type ProblemSeverity = "info" | "warning" | "error" |
|
||||
/** The refactoring can't run at all; there is no edit. */
|
||||
"fatal";
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import { act, cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ActionContext } from "@/platform/actions";
|
||||
import type { Settings } from "@/platform/ipc";
|
||||
|
||||
const settingsSet = vi.fn();
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return {
|
||||
...real,
|
||||
isTauri: () => true,
|
||||
commands: { ...real.commands, settingsSet: (...a: unknown[]) => settingsSet(...a) },
|
||||
};
|
||||
});
|
||||
|
||||
import { executeAction, registerActions } from "@/platform/actions";
|
||||
import { useKeymap } from "@/platform/keymap";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { presentationAssistantAction } from "../appearanceRuntime";
|
||||
import { validateAppearanceExtras } from "../model/behaviorSchema";
|
||||
import { PresentationAssistant } from "../presentation/PresentationAssistant";
|
||||
import { alternatePreset, presentAction } from "../presentation/presentation";
|
||||
|
||||
let assistant: Record<string, unknown>;
|
||||
const disposers: Array<() => void> = [];
|
||||
|
||||
function useSettings(patch: Record<string, unknown>) {
|
||||
assistant = { ...assistant, ...patch };
|
||||
useProject.setState({ settings: { appearance: { presentationAssistant: { ...assistant } } } as unknown as Settings });
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
assistant = {};
|
||||
useSettings({});
|
||||
usePlatform.setState({ os: "macos" });
|
||||
useKeymap.setState({ preset: "intellij-macos", overrides: {}, extensions: {} });
|
||||
disposers.push(
|
||||
registerActions([
|
||||
{ id: "file.save", title: "Save All", category: "File", run: () => {} },
|
||||
{ id: "test.unbound", title: "Unbound Action", run: () => {} },
|
||||
{ id: "test.internal", title: "Internal Step", hidden: true, run: () => {} },
|
||||
]),
|
||||
);
|
||||
settingsSet.mockReset().mockImplementation(async (_scope: string, key: string, json: string) => {
|
||||
useSettings({ [key.replace("appearance.presentationAssistant.", "")]: JSON.parse(json) });
|
||||
return { status: "ok", data: useProject.getState().settings };
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
while (disposers.length) disposers.pop()!();
|
||||
useProject.setState({ settings: null });
|
||||
});
|
||||
|
||||
describe("Presentation Assistant", () => {
|
||||
it("is off by default and keeps its options in range", () => {
|
||||
expect(validateAppearanceExtras({}).presentationAssistant).toEqual({
|
||||
enabled: false,
|
||||
size: "medium",
|
||||
durationSeconds: 4,
|
||||
position: "bottom",
|
||||
alternateKeymap: false,
|
||||
});
|
||||
expect(
|
||||
validateAppearanceExtras({ presentationAssistant: { size: "huge", durationSeconds: 0, position: "middle" } })
|
||||
.presentationAssistant,
|
||||
).toMatchObject({ size: "medium", durationSeconds: 1, position: "bottom" });
|
||||
});
|
||||
|
||||
it("names the action with its shortcut, and the other platform's on request", () => {
|
||||
expect(presentAction("file.save", false)).toEqual({ title: "Save All", shortcut: "⌘S" });
|
||||
expect(presentAction("file.save", true)).toEqual({
|
||||
title: "Save All",
|
||||
shortcut: "⌘S",
|
||||
alternate: { keymap: "Windows/Linux", shortcut: "Ctrl+S" },
|
||||
});
|
||||
expect(presentAction("file.save", true, false)?.alternate).toEqual({ keymap: "macOS", shortcut: "⌘S" });
|
||||
expect(presentAction("test.unbound", true)).toEqual({ title: "Unbound Action", shortcut: undefined });
|
||||
expect(presentAction("test.internal", false)).toBeNull();
|
||||
expect(alternatePreset("vscode-macos", true)).toBe("vscode-windows");
|
||||
expect(alternatePreset("my-custom-keymap", false)).toBe("intellij-macos");
|
||||
});
|
||||
|
||||
it("shows each action run while enabled and hides it after the duration", async () => {
|
||||
vi.useFakeTimers();
|
||||
render(<PresentationAssistant />);
|
||||
await act(async () => void (await executeAction("file.save")));
|
||||
expect(screen.queryByTestId("presentation-assistant")).toBeNull();
|
||||
|
||||
act(() => useSettings({ enabled: true, durationSeconds: 2 }));
|
||||
await act(async () => void (await executeAction("file.save")));
|
||||
expect(screen.getByTestId("presentation-assistant").textContent).toBe("Save All⌘S");
|
||||
|
||||
act(() => vi.advanceTimersByTime(1500));
|
||||
expect(screen.getByTestId("presentation-assistant")).toBeTruthy();
|
||||
act(() => vi.advanceTimersByTime(600));
|
||||
expect(screen.queryByTestId("presentation-assistant")).toBeNull();
|
||||
});
|
||||
|
||||
it("is toggled from View › Appearance", async () => {
|
||||
const action = presentationAssistantAction();
|
||||
expect(action.toggled?.()).toBe(false);
|
||||
await action.run({ ctx: {} } as ActionContext);
|
||||
expect(settingsSet).toHaveBeenCalledWith("global", "appearance.presentationAssistant.enabled", "true");
|
||||
expect(action.toggled?.()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -208,6 +208,26 @@ export function appearanceToggleActions(): Action[] {
|
||||
];
|
||||
}
|
||||
|
||||
/** View › Appearance › Presentation Assistant. */
|
||||
export function presentationAssistantAction(): Action {
|
||||
const enabled = () => validateSettings(useProject.getState().settings).appearance.presentationAssistant.enabled;
|
||||
return {
|
||||
id: "view.togglePresentationAssistant",
|
||||
title: "Presentation Assistant",
|
||||
category: "View",
|
||||
keywords: ["appearance", "show shortcuts", "action names", "screencast", "demo", "key promoter"],
|
||||
toggled: enabled,
|
||||
run: async () => {
|
||||
if (!isTauri()) return;
|
||||
useProject.setState({
|
||||
settings: await call(
|
||||
commands.settingsSet("global", "appearance.presentationAssistant.enabled", JSON.stringify(!enabled())),
|
||||
),
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// View › Appearance › Navigation Bar: a radio choice (Top / Status Bar / hidden)
|
||||
|
||||
|
||||
@@ -38,7 +38,13 @@ import {
|
||||
settingsTitle,
|
||||
useSettingsDialog,
|
||||
} from "./model/staging";
|
||||
import { appearanceToggleActions, navigationBarActions, zoomActions } from "./appearanceRuntime";
|
||||
import {
|
||||
appearanceToggleActions,
|
||||
navigationBarActions,
|
||||
presentationAssistantAction,
|
||||
zoomActions,
|
||||
} from "./appearanceRuntime";
|
||||
import { PresentationAssistant } from "./presentation/PresentationAssistant";
|
||||
import { activateFileTypes } from "./fileTypesRuntime";
|
||||
import { trackRuntimeSettings } from "./runtime";
|
||||
import { installActionProxies, installSettingsHost } from "./window/bridge";
|
||||
@@ -129,6 +135,8 @@ export function activate(): () => void {
|
||||
registerOverlay({ id: "settings.projectStructure", component: LazyProjectStructureDialog }),
|
||||
registerActions(zoomActions()),
|
||||
registerActions(appearanceToggleActions()),
|
||||
registerActions([presentationAssistantAction()]),
|
||||
registerOverlay({ id: "settings.presentationAssistant", component: PresentationAssistant }),
|
||||
registerActions(navigationBarActions()),
|
||||
registerActions(settingsActions((page, newProjects) => void showSettings(page, newProjects))),
|
||||
registerActions([
|
||||
|
||||
@@ -35,6 +35,27 @@ export interface BackgroundImageValid {
|
||||
fill: BackgroundImageFill;
|
||||
anchor: BackgroundImageAnchor;
|
||||
}
|
||||
export type PresentationAssistantSize = "small" | "medium" | "large";
|
||||
export const PRESENTATION_ASSISTANT_POSITIONS = [
|
||||
"top-left",
|
||||
"top",
|
||||
"top-right",
|
||||
"bottom-left",
|
||||
"bottom",
|
||||
"bottom-right",
|
||||
] as const;
|
||||
export type PresentationAssistantPosition = (typeof PRESENTATION_ASSISTANT_POSITIONS)[number];
|
||||
export const PRESENTATION_ASSISTANT_DURATION = { min: 1, max: 60 } as const;
|
||||
|
||||
/** Appearance › Presentation Assistant: the name and shortcut of each action the user runs. */
|
||||
export interface PresentationAssistantValid {
|
||||
enabled: boolean;
|
||||
size: PresentationAssistantSize;
|
||||
durationSeconds: number;
|
||||
position: PresentationAssistantPosition;
|
||||
/** Also show the other platform's shortcut (macOS ⇄ Windows/Linux). */
|
||||
alternateKeymap: boolean;
|
||||
}
|
||||
/** Themes selectable as "preferred" when syncing with the OS. */
|
||||
export type ConcreteTheme = ThemeChoiceId;
|
||||
|
||||
@@ -77,6 +98,7 @@ export interface AppearanceExtras {
|
||||
* the editor, in the status bar, or not at all. */
|
||||
navigationBar: NavigationBarPosition;
|
||||
backgroundImage: BackgroundImageValid;
|
||||
presentationAssistant: PresentationAssistantValid;
|
||||
}
|
||||
|
||||
export interface DateFormatValid {
|
||||
@@ -156,6 +178,13 @@ export const DEFAULT_APPEARANCE_EXTRAS: AppearanceExtras = {
|
||||
showStatusBar: true,
|
||||
navigationBar: "statusBar",
|
||||
backgroundImage: { path: "", opacity: 15, fill: "scale", anchor: "center" },
|
||||
presentationAssistant: {
|
||||
enabled: false,
|
||||
size: "medium",
|
||||
durationSeconds: 4,
|
||||
position: "bottom",
|
||||
alternateKeymap: false,
|
||||
},
|
||||
};
|
||||
|
||||
const NAV_BAR_POSITIONS: readonly NavigationBarPosition[] = ["top", "statusBar", "hidden"];
|
||||
@@ -238,6 +267,19 @@ export function validateAppearanceExtras(raw: unknown): AppearanceExtras {
|
||||
return oneOf(a.navigationBar, NAV_BAR_POSITIONS, d.navigationBar);
|
||||
})(),
|
||||
backgroundImage: validateBackgroundImage(a.backgroundImage),
|
||||
presentationAssistant: validatePresentationAssistant(a.presentationAssistant),
|
||||
};
|
||||
}
|
||||
|
||||
function validatePresentationAssistant(raw: unknown): PresentationAssistantValid {
|
||||
const p = obj(raw);
|
||||
const d = DEFAULT_APPEARANCE_EXTRAS.presentationAssistant;
|
||||
return {
|
||||
enabled: bool(p.enabled, d.enabled),
|
||||
size: oneOf(p.size, ["small", "medium", "large"], d.size),
|
||||
durationSeconds: int(p.durationSeconds, d.durationSeconds, PRESENTATION_ASSISTANT_DURATION),
|
||||
position: oneOf(p.position, PRESENTATION_ASSISTANT_POSITIONS, d.position),
|
||||
alternateKeymap: bool(p.alternateKeymap, d.alternateKeymap),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ import {
|
||||
type NotificationGroupValid,
|
||||
type NavigationBarPosition,
|
||||
type OpenProjectIn,
|
||||
PRESENTATION_ASSISTANT_DURATION,
|
||||
type PresentationAssistantPosition,
|
||||
type PresentationAssistantSize,
|
||||
} from "../model/behaviorSchema";
|
||||
import { ACCENT_PRESETS, LIMITS, type ThemeId } from "../model/schema";
|
||||
import type { PageSpec } from "./spec";
|
||||
@@ -393,6 +396,21 @@ const AA_OPTIONS: SelectOption<Antialiasing>[] = [
|
||||
{ value: "none", label: "No antialiasing" },
|
||||
];
|
||||
|
||||
const PRESENTATION_SIZE_OPTIONS: SelectOption<PresentationAssistantSize>[] = [
|
||||
{ value: "small", label: "Small" },
|
||||
{ value: "medium", label: "Medium" },
|
||||
{ value: "large", label: "Large" },
|
||||
];
|
||||
|
||||
const PRESENTATION_POSITION_OPTIONS: SelectOption<PresentationAssistantPosition>[] = [
|
||||
{ value: "top-left", label: "Top left" },
|
||||
{ value: "top", label: "Top center" },
|
||||
{ value: "top-right", label: "Top right" },
|
||||
{ value: "bottom-left", label: "Bottom left" },
|
||||
{ value: "bottom", label: "Bottom center" },
|
||||
{ value: "bottom-right", label: "Bottom right" },
|
||||
];
|
||||
|
||||
const NAV_BAR_OPTIONS: SelectOption<NavigationBarPosition>[] = [
|
||||
{ value: "top", label: "Top" },
|
||||
{ value: "statusBar", label: "Status Bar" },
|
||||
@@ -966,6 +984,50 @@ export const BEHAVIOR_PAGES: PageSpec[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "appearance.presentationAssistant",
|
||||
title: "Presentation Assistant",
|
||||
order: 0,
|
||||
keywords: ["action names", "shortcuts", "screencast", "demo", "presentation"],
|
||||
sections: [
|
||||
{
|
||||
options: [
|
||||
{
|
||||
kind: "toggle",
|
||||
key: "appearance.presentationAssistant.enabled",
|
||||
label: "Show action names and shortcuts",
|
||||
hint: "Each action you run shows its name and shortcut in a popup, for screencasts and demos.",
|
||||
},
|
||||
{
|
||||
kind: "select",
|
||||
key: "appearance.presentationAssistant.size",
|
||||
label: "Popup size",
|
||||
options: PRESENTATION_SIZE_OPTIONS,
|
||||
},
|
||||
{
|
||||
kind: "number",
|
||||
key: "appearance.presentationAssistant.durationSeconds",
|
||||
label: "Duration",
|
||||
...PRESENTATION_ASSISTANT_DURATION,
|
||||
integer: true,
|
||||
unit: "seconds",
|
||||
},
|
||||
{
|
||||
kind: "select",
|
||||
key: "appearance.presentationAssistant.position",
|
||||
label: "Popup position",
|
||||
options: PRESENTATION_POSITION_OPTIONS,
|
||||
},
|
||||
{
|
||||
kind: "toggle",
|
||||
key: "appearance.presentationAssistant.alternateKeymap",
|
||||
label: "Also show the other platform's shortcut",
|
||||
hint: "macOS shortcuts on Windows and Linux, Windows/Linux shortcuts on macOS.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "general",
|
||||
title: "System Settings",
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
.popup {
|
||||
position: fixed;
|
||||
z-index: var(--z-toast);
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--space-3);
|
||||
max-width: calc(100vw - 32px);
|
||||
padding: var(--space-3) var(--space-4);
|
||||
border: 1px solid var(--border-popup);
|
||||
border-radius: var(--radius-popup-large);
|
||||
background: var(--bg-popup);
|
||||
box-shadow: var(--shadow-popup);
|
||||
color: var(--fg-strong);
|
||||
pointer-events: none;
|
||||
white-space: nowrap;
|
||||
animation: fade-in 120ms ease-out;
|
||||
}
|
||||
|
||||
.leaving {
|
||||
opacity: 0;
|
||||
transition: opacity 300ms ease-in;
|
||||
}
|
||||
|
||||
.top-left,
|
||||
.top,
|
||||
.top-right {
|
||||
top: 56px;
|
||||
}
|
||||
|
||||
.bottom-left,
|
||||
.bottom,
|
||||
.bottom-right {
|
||||
bottom: 48px;
|
||||
}
|
||||
|
||||
.top-left,
|
||||
.bottom-left {
|
||||
left: 24px;
|
||||
}
|
||||
|
||||
.top-right,
|
||||
.bottom-right {
|
||||
right: 24px;
|
||||
}
|
||||
|
||||
.top,
|
||||
.bottom {
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.shortcut {
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
|
||||
.keymap {
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.medium {
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.large {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.small .shortcut,
|
||||
.small .keymap {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.medium .shortcut,
|
||||
.medium .keymap {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.large .shortcut,
|
||||
.large .keymap {
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.popup {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.leaving {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { onActionExecuted } from "@/platform/actions";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { validateSettings } from "../model/schema";
|
||||
import { presentAction, type PresentedAction } from "./presentation";
|
||||
import styles from "./PresentationAssistant.module.css";
|
||||
|
||||
const FADE_MS = 300;
|
||||
|
||||
/** Appearance › Presentation Assistant: the name and shortcut of each action the user runs. */
|
||||
export function PresentationAssistant() {
|
||||
const raw = useProject((s) => s.settings);
|
||||
const settings = useMemo(() => validateSettings(raw).appearance.presentationAssistant, [raw]);
|
||||
const [shown, setShown] = useState<{ action: PresentedAction; key: number; leaving: boolean } | null>(null);
|
||||
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
||||
const { enabled, durationSeconds, alternateKeymap } = settings;
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
let key = 0;
|
||||
const clear = () => {
|
||||
for (const t of timers.current) clearTimeout(t);
|
||||
timers.current = [];
|
||||
};
|
||||
const off = onActionExecuted((id) => {
|
||||
const action = presentAction(id, alternateKeymap);
|
||||
if (!action) return;
|
||||
clear();
|
||||
const current = ++key;
|
||||
setShown({ action, key: current, leaving: false });
|
||||
const hold = Math.max(0, durationSeconds * 1000 - FADE_MS);
|
||||
timers.current.push(
|
||||
setTimeout(() => setShown((s) => (s?.key === current ? { ...s, leaving: true } : s)), hold),
|
||||
setTimeout(() => setShown((s) => (s?.key === current ? null : s)), hold + FADE_MS),
|
||||
);
|
||||
});
|
||||
return () => {
|
||||
off();
|
||||
clear();
|
||||
// A popup whose timers were just cleared would otherwise stay up.
|
||||
setShown(null);
|
||||
};
|
||||
}, [enabled, durationSeconds, alternateKeymap]);
|
||||
|
||||
if (!enabled || !shown) return null;
|
||||
const { action, leaving } = shown;
|
||||
return (
|
||||
<div
|
||||
className={[styles.popup, styles[settings.size], styles[settings.position], leaving && styles.leaving]
|
||||
.filter(Boolean)
|
||||
.join(" ")}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
data-testid="presentation-assistant"
|
||||
>
|
||||
<span className={styles.title}>{action.title}</span>
|
||||
{action.shortcut && <span className={styles.shortcut}>{action.shortcut}</span>}
|
||||
{action.alternate && (
|
||||
<span className={styles.keymap}>
|
||||
{action.alternate.shortcut} ({action.alternate.keymap})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -442,6 +442,7 @@
|
||||
"menu.navigate.nextBookmark": "Next Bookmark",
|
||||
"menu.navigate.prevBookmark": "Previous Bookmark",
|
||||
"menu.view.toggleCompactMode": "Compact Mode",
|
||||
"menu.view.togglePresentationAssistant": "Presentation Assistant",
|
||||
"menu.view.zoomIn": "Zoom In IDE",
|
||||
"menu.view.zoomOut": "Zoom Out IDE",
|
||||
"menu.view.resetZoom": "Reset IDE Zoom",
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"Presentation Assistant": "Presentation Assistant",
|
||||
"Small": "Small",
|
||||
"Large": "Large",
|
||||
"Top center": "Top center",
|
||||
"Bottom center": "Bottom center",
|
||||
"Show action names and shortcuts": "Show action names and shortcuts",
|
||||
"Each action you run shows its name and shortcut in a popup, for screencasts and demos.": "Each action you run shows its name and shortcut in a popup, for screencasts and demos.",
|
||||
"Popup size": "Popup size",
|
||||
"Duration": "Duration",
|
||||
"Popup position": "Popup position",
|
||||
"Also show the other platform's shortcut": "Also show the other platform's shortcut",
|
||||
"macOS shortcuts on Windows and Linux, Windows/Linux shortcuts on macOS.": "macOS shortcuts on Windows and Linux, Windows/Linux shortcuts on macOS.",
|
||||
"Trust Project in Codex": "Trust Project in Codex",
|
||||
"Go to Feign Endpoint": "Go to Feign Endpoint",
|
||||
"Choose Feign Endpoint": "Choose Feign Endpoint",
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"Presentation Assistant": "演示助手",
|
||||
"Small": "小",
|
||||
"Large": "大",
|
||||
"Top center": "顶部居中",
|
||||
"Bottom center": "底部居中",
|
||||
"Show action names and shortcuts": "显示操作名称和快捷键",
|
||||
"Each action you run shows its name and shortcut in a popup, for screencasts and demos.": "每次执行操作时在弹出窗口中显示其名称和快捷键,适合录屏和演示。",
|
||||
"Popup size": "弹出窗口大小",
|
||||
"Duration": "持续时间",
|
||||
"Popup position": "弹出窗口位置",
|
||||
"Also show the other platform's shortcut": "同时显示另一平台的快捷键",
|
||||
"macOS shortcuts on Windows and Linux, Windows/Linux shortcuts on macOS.": "在 Windows 和 Linux 上显示 macOS 快捷键,在 macOS 上显示 Windows/Linux 快捷键。",
|
||||
"Trust Project in Codex": "在 Codex 中信任项目",
|
||||
"Go to Feign Endpoint": "跳转到 Feign 端点",
|
||||
"Choose Feign Endpoint": "选择 Feign 端点",
|
||||
|
||||
@@ -442,6 +442,7 @@
|
||||
"menu.navigate.nextBookmark": "下一个书签",
|
||||
"menu.navigate.prevBookmark": "上一个书签",
|
||||
"menu.view.toggleCompactMode": "紧凑模式",
|
||||
"menu.view.togglePresentationAssistant": "演示助手",
|
||||
"menu.view.zoomIn": "放大 IDE",
|
||||
"menu.view.zoomOut": "缩小 IDE",
|
||||
"menu.view.resetZoom": "重置 IDE 缩放",
|
||||
|
||||
Reference in New Issue
Block a user