@devries-cameron20 / t3code Mirror · read-only / commits / eb51389e4e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(desktop): keypad shortcuts and Ctrl+wheel zoom the app (#21200)

Co-authored-by: Mnigos <56691628+Mnigos@users.noreply.github.com>

Reda Hilal committed Oct 18, 2026 at 23:52 UTC eb51389e4eac006edae17c52b9fcc1c32846c6cd
4 files changed +108 -9
apps/desktop/src/window/DesktopApplicationMenu.test.ts
+31
@@ -280,6 +280,37 @@ describe("DesktopApplicationMenu", () => {
280 }),
281 );
282
283 + it.effect("zooms from the numeric keypad without listing the commands twice", () =>
284 + Effect.gen(function* () {
285 + for (const [accelerator, expected] of [
286 + ["CmdOrCtrl+numadd", "zoom-in"],
287 + ["CmdOrCtrl+numsub", "zoom-out"],
288 + ["CmdOrCtrl+num0", "zoom-reset"],
289 + ] as const) {
290 + const selectedAction = yield* Deferred.make<string>();
291 + const applicationMenuTemplate =
292 + yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
293 +
294 + yield* configureMenu(selectedAction, applicationMenuTemplate);
295 +
296 + const template = yield* Deferred.await(applicationMenuTemplate);
297 + const viewMenu = template.find((item) => item.label === "View");
298 + if (!viewMenu || !Array.isArray(viewMenu.submenu)) {
299 + throw new Error("Expected View menu submenu to be an array.");
300 + }
301 + const item = viewMenu.submenu.find((entry) => entry.accelerator === accelerator);
302 + assert.isDefined(item);
303 + assert.isFalse(item.visible);
304 + if (typeof item.click !== "function") {
305 + throw new Error(`Expected ${accelerator} menu item to have a click handler.`);
306 + }
307 +
308 + item.click({} as Electron.MenuItem, {} as Electron.BrowserWindow, {} as KeyboardEvent);
309 + assert.equal(yield* Deferred.await(selectedAction), expected);
310 + }
311 + }),
312 + );
313 +
314 it.effect("reloads the main window even while a browser page has focus", () =>
315 Effect.gen(function* () {
316 const selectedAction = yield* Deferred.make<string>();
apps/desktop/src/window/DesktopApplicationMenu.ts
+20
@@ -264,6 +264,26 @@ export const make = Effect.gen(function* () {
264 click: zoomClick("in"),
265 },
266 { label: "Zoom Out", accelerator: "CmdOrCtrl+-", click: zoomClick("out") },
267 + // The numeric keypad sends its own key codes, so the number-row
268 + // accelerators above never match it.
269 + {
270 + label: "Actual Size",
271 + accelerator: "CmdOrCtrl+num0",
272 + visible: false,
273 + click: zoomClick("reset"),
274 + },
275 + {
276 + label: "Zoom In",
277 + accelerator: "CmdOrCtrl+numadd",
278 + visible: false,
279 + click: zoomClick("in"),
280 + },
281 + {
282 + label: "Zoom Out",
283 + accelerator: "CmdOrCtrl+numsub",
284 + visible: false,
285 + click: zoomClick("out"),
286 + },
287 { type: "separator" },
288 { role: "togglefullscreen" },
289 ],
apps/desktop/src/window/DesktopWindow.test.ts
+34
@@ -798,6 +798,40 @@ describe("DesktopWindow", () => {
798 }),
799 );
800
801 + // Ctrl+wheel bypasses the menu accelerators, so it has to take the same
802 + // zoom step, preview restore included, from the window's zoom-changed event.
803 + it.effect("zooms the app from Ctrl+wheel like the menu does", () =>
804 + Effect.gen(function* () {
805 + const fakeWindow = makeFakeBrowserWindow();
806 + const createCount = yield* Ref.make(0);
807 + const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
808 + const previewZoomReapplies: number[] = [];
809 + const layer = layerTest({
810 + window: fakeWindow.window,
811 + createCount,
812 + mainWindow,
813 + previewZoomReapplies,
814 + });
815 +
816 + yield* Effect.gen(function* () {
817 + const desktopWindow = yield* DesktopWindow.DesktopWindow;
818 + yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
819 +
820 + const zoomChanged = fakeWindow.webContentsListeners.get("zoom-changed");
821 + if (!zoomChanged) return yield* Effect.die("zoom-changed listener was not registered");
822 + zoomChanged({}, "in");
823 + zoomChanged({}, "out");
824 + zoomChanged({}, "out");
825 +
826 + assert.deepEqual(
827 + fakeWindow.setZoomLevel.mock.calls.map(([level]) => level),
828 + [0.5, 0, -0.5],
829 + );
830 + assert.deepEqual(previewZoomReapplies, [0.5, 0, -0.5]);
831 + }).pipe(Effect.provide(layer));
832 + }),
833 + );
834 +
835 it.effect("reloads and inspects the main window even when a popup has focus", () =>
836 Effect.gen(function* () {
837 const fakeWindow = makeFakeBrowserWindow();
apps/desktop/src/window/DesktopWindow.ts
+23 -9
@@ -329,6 +329,21 @@ export const make = Effect.gen(function* () {
329 const currentMainWindow = electronWindow.currentMainOrFirst.pipe(Effect.flatMap(withoutSplash));
330 const focusedMainWindow = electronWindow.focusedMainOrFirst.pipe(Effect.flatMap(withoutSplash));
331
332 + const zoomWindow = Effect.fn("desktop.window.zoomWindow")(function* (
333 + window: Electron.BrowserWindow,
334 + direction: MainWindowZoomDirection,
335 + ) {
336 + const webContents = window.webContents;
337 + webContents.setZoomLevel(
338 + direction === "reset" ? 0 : webContents.getZoomLevel() + (direction === "in" ? 0.5 : -0.5),
339 + );
340 + if (environment.platform === "darwin") syncMacosWindowButtons(window);
341 + // Chromium pushes the new level down to embedded guests, which would zoom
342 + // the previewed page along with the app UI. The preview browser keeps its
343 + // own zoom, so put each guest back where the preview left it.
344 + yield* previewManager.reapplyZoom();
345 + });
346 +
347 const createWindow = Effect.fn("desktop.window.createWindow")(function* (): Effect.fn.Return<
348 Electron.BrowserWindow,
349 DesktopWindowError
@@ -645,6 +660,13 @@ export const make = Effect.gen(function* () {
660 window.webContents.on("input-event", (_event, input) => {
661 if (input.type === "gestureScrollEnd") window.webContents.send(TRACKPAD_SCROLL_END_CHANNEL);
662 });
663 + // Ctrl+wheel never reaches the menu accelerators: Chromium reports it here
664 + // and leaves applying the zoom to the app. A preview guest under the
665 + // pointer emits this on its own webContents and keeps its own zoom.
666 + window.webContents.on("zoom-changed", (_event, direction) => {
667 + if (window.isDestroyed()) return;
668 + runFork(zoomWindow(window, direction));
669 + });
670
671 window.on("page-title-updated", (event) => {
672 event.preventDefault();
@@ -976,15 +998,7 @@ export const make = Effect.gen(function* () {
998 if (Option.isNone(window) || window.value.isDestroyed()) {
999 return;
1000 }
979 - const webContents = window.value.webContents;
980 - webContents.setZoomLevel(
981 - direction === "reset" ? 0 : webContents.getZoomLevel() + (direction === "in" ? 0.5 : -0.5),
982 - );
983 - if (environment.platform === "darwin") syncMacosWindowButtons(window.value);
984 - // Chromium pushes the new level down to embedded guests, which would zoom
985 - // the previewed page along with the app UI. The preview browser keeps its
986 - // own zoom, so put each guest back where the preview left it.
987 - yield* previewManager.reapplyZoom();
1001 + yield* zoomWindow(window.value, direction);
1002 }),
1003 runMainContentsCommand: Effect.fn("desktop.window.runMainContentsCommand")(function* (command) {
1004 yield* Effect.annotateCurrentSpan({ command });