Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/code/src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import { saveZoomLevel } from "./utils/store";
// Zoom is measured in Electron "levels" (factor = 1.2 ** level; 0 = 100%).
// ZOOM_STEP is one Zoom In/Out notch; the bounds clamp the level so a runaway
// accelerator can't persist an unusable zoom across restarts.
const ZOOM_STEP = 0.5;
export const ZOOM_STEP = 0.5;
const ZOOM_MIN = -3;
const ZOOM_MAX = 3;

// Apply a zoom change to the focused window and persist the new level so it
// survives restarts. `delta` adjusts relative to the current level; "reset"
// returns to 100%.
function applyZoom(delta: number | "reset"): void {
export function applyZoom(delta: number | "reset"): void {
const webContents = BrowserWindow.getFocusedWindow()?.webContents;
if (!webContents) return;
const next = delta === "reset" ? 0 : webContents.getZoomLevel() + delta;
Expand Down
13 changes: 13 additions & 0 deletions apps/code/src/main/platform-adapters/electron-main-window.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IMainWindow } from "@posthog/platform/main-window";
import { app, type BrowserWindow } from "electron";
import { injectable } from "inversify";
import { applyZoom, ZOOM_STEP } from "../menu";

@injectable()
export class ElectronMainWindow implements IMainWindow {
Expand Down Expand Up @@ -35,4 +36,16 @@ export class ElectronMainWindow implements IMainWindow {
app.on("browser-window-focus", listener);
return () => app.off("browser-window-focus", listener);
}

public zoomIn(): void {
applyZoom(ZOOM_STEP);
}

public zoomOut(): void {
applyZoom(-ZOOM_STEP);
}

public resetZoom(): void {
applyZoom("reset");
}
}
16 changes: 16 additions & 0 deletions packages/host-router/src/routers/os.router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { publicProcedure, router } from "@posthog/host-trpc/trpc";
import {
type IMainWindow,
MAIN_WINDOW_SERVICE,
} from "@posthog/platform/main-window";
import { OS_SERVICE } from "@posthog/workspace-server/services/os/identifiers";
import type { OsService } from "@posthog/workspace-server/services/os/os";
import {
Expand Down Expand Up @@ -120,4 +124,16 @@ export const osRouter = router({
.get<OsService>(OS_SERVICE)
.saveClipboardFile(input.base64Data, input.originalName),
),

zoomIn: publicProcedure.mutation(({ ctx }) =>
ctx.container.get<IMainWindow>(MAIN_WINDOW_SERVICE).zoomIn(),
),

zoomOut: publicProcedure.mutation(({ ctx }) =>
ctx.container.get<IMainWindow>(MAIN_WINDOW_SERVICE).zoomOut(),
),

resetZoom: publicProcedure.mutation(({ ctx }) =>
ctx.container.get<IMainWindow>(MAIN_WINDOW_SERVICE).resetZoom(),
),
});
3 changes: 3 additions & 0 deletions packages/platform/src/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export interface IMainWindow {
isMinimized(): boolean;
restore(): void;
onFocus(handler: () => void): () => void;
zoomIn(): void;
zoomOut(): void;
resetZoom(): void;
}

export const MAIN_WINDOW_SERVICE = Symbol.for("posthog.platform.mainWindow");
5 changes: 4 additions & 1 deletion packages/shared/src/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export type CommandMenuAction =
| "search-files"
| "open-file"
| "reload-window"
| "show-log-folder";
| "show-log-folder"
| "zoom-in"
| "zoom-out"
| "zoom-reset";

// Event property interfaces
export interface TaskListViewProperties {
Expand Down
47 changes: 47 additions & 0 deletions packages/ui/src/features/command/CommandMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CaretLeftIcon, CaretRightIcon, HashIcon } from "@phosphor-icons/react";
import { resolveService } from "@posthog/di/container";
import {
HOST_TRPC_CLIENT,
type HostTrpcClient,
} from "@posthog/host-router/client";
import {
Autocomplete,
AutocompleteCollection,
Expand Down Expand Up @@ -58,6 +63,8 @@ import {
ReloadIcon,
SunIcon,
ViewVerticalIcon,
ZoomInIcon,
ZoomOutIcon,
} from "@radix-ui/react-icons";
import { useCallback, useEffect, useMemo, useState } from "react";

Expand Down Expand Up @@ -319,9 +326,49 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
},
];

const view: Command[] = [
{
id: "zoom-in",
label: "Zoom in",
keywords: "zoom increase larger",
icon: <ZoomInIcon className="h-3 w-3 text-gray-11" />,
action: "zoom-in",
shortcut: SHORTCUTS.ZOOM_IN,
onRun: () =>
void resolveService<HostTrpcClient>(
HOST_TRPC_CLIENT,
).os.zoomIn.mutate(),
},
{
id: "zoom-out",
label: "Zoom out",
keywords: "zoom decrease smaller",
icon: <ZoomOutIcon className="h-3 w-3 text-gray-11" />,
action: "zoom-out",
shortcut: SHORTCUTS.ZOOM_OUT,
onRun: () =>
void resolveService<HostTrpcClient>(
HOST_TRPC_CLIENT,
).os.zoomOut.mutate(),
},
{
id: "zoom-reset",
label: "Reset zoom",
keywords: "zoom actual size default",
icon: <MagnifyingGlassIcon className="h-3 w-3 text-gray-11" />,
action: "zoom-reset",
shortcut: SHORTCUTS.RESET_ZOOM,
onRun: () =>
void resolveService<HostTrpcClient>(
HOST_TRPC_CLIENT,
).os.resetZoom.mutate(),
},
];
Comment on lines +329 to +366

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 view shadows the outer useAppView() result

The local const view: Command[] declared inside the commandSections useMemo uses the same name as the component-level const view = useAppView() at line 137. There is no actual bug today (the outer view is consumed before the useMemo via reviewTaskId), but any future edit inside this closure that mistakenly writes view.type instead of reviewTaskId will silently read the Command[] array rather than the router view. A distinct name like viewCommands avoids the trap entirely.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


const out: CommandSection[] = [
{ label: "Actions", items: actions },
{ label: "Navigation", items: navigation },
{ label: "View", items: view },
{ label: "Developer", items: developer },
];

Expand Down
5 changes: 5 additions & 0 deletions packages/ui/src/features/command/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const SHORTCUTS = {
SUBMIT_BLUR: "mod+enter",
SWITCH_MESSAGING_MODE: "mod+s",
RELOAD_WINDOW: "mod+shift+r",
ZOOM_IN: "mod+=",
ZOOM_OUT: "mod+-",
RESET_ZOOM: "mod+0",
Comment on lines +29 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Zoom shortcuts not added to KEYBOARD_SHORTCUTS reference array

ZOOM_IN, ZOOM_OUT, and RESET_ZOOM are registered in SHORTCUTS and will display correctly in the command palette, but none of them are added to the KEYBOARD_SHORTCUTS array (line 45 onwards). That array drives the "Show keyboard shortcuts" sheet (mod+/), so users consulting that reference will have no indication the zoom shortcuts exist.

} as const;

export type ShortcutCategory = "general" | "navigation" | "panels" | "editor";
Expand Down Expand Up @@ -256,6 +259,8 @@ function formatKey(key: string): string {
if (k === ",") return ",";
if (k === "[") return "[";
if (k === "]") return "]";
if (k === "=") return "+";
if (k === "-") return "-";
if (k === "tab") return "Tab";
return k.toUpperCase();
}
Expand Down
Loading