Skip to content
Merged
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 @@ -56,7 +56,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
Expand Up @@ -4,6 +4,11 @@ import {
EnvelopeSimple,
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 @@ -66,6 +71,8 @@ import {
ReloadIcon,
SunIcon,
ViewVerticalIcon,
ZoomInIcon,
ZoomOutIcon,
} from "@radix-ui/react-icons";
import { useCallback, useEffect, useMemo, useState } from "react";

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

const viewCommands: 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(),
},
];

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

Expand Down
23 changes: 23 additions & 0 deletions packages/ui/src/features/command/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 thread
MattPua marked this conversation as resolved.
} as const;

export type ShortcutCategory = "general" | "navigation" | "panels" | "editor";
Expand Down Expand Up @@ -69,6 +72,24 @@ export const KEYBOARD_SHORTCUTS: KeyboardShortcut[] = [
description: "Show keyboard shortcuts",
category: "general",
},
{
id: "zoom-in",
keys: SHORTCUTS.ZOOM_IN,
description: "Zoom in",
category: "general",
},
{
id: "zoom-out",
keys: SHORTCUTS.ZOOM_OUT,
description: "Zoom out",
category: "general",
},
{
id: "reset-zoom",
keys: SHORTCUTS.RESET_ZOOM,
description: "Reset zoom",
category: "general",
},
{
id: "switch-messaging-mode",
keys: SHORTCUTS.SWITCH_MESSAGING_MODE,
Expand Down Expand Up @@ -264,6 +285,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