Skip to content

Commit fcab788

Browse files
fix(desktop): handle macos command-plus zoom input (pingdotgg#18439)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 5cf3854 commit fcab788

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ describe("DesktopApplicationMenu", () => {
247247
}),
248248
);
249249

250-
it.effect("routes View menu zoom to the main window instead of zoom roles", () =>
250+
it.effect("registers macOS command-plus once and routes it through main-window zoom", () =>
251251
Effect.gen(function* () {
252252
const selectedAction = yield* Deferred.make<string>();
253253
const applicationMenuTemplate =
254254
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
255255

256-
yield* configureMenu(selectedAction, applicationMenuTemplate);
256+
yield* configureMenu(selectedAction, applicationMenuTemplate, { platform: "darwin" });
257257

258258
const template = yield* Deferred.await(applicationMenuTemplate);
259259
const viewMenu = template.find((item) => item.label === "View");
@@ -268,9 +268,17 @@ describe("DesktopApplicationMenu", () => {
268268
),
269269
);
270270

271-
const zoomIn = viewMenu.submenu.find((item) => item.label === "Zoom In");
271+
const shiftedEqual = viewMenu.submenu.filter(
272+
(item) => item.accelerator === "CmdOrCtrl+Shift+=",
273+
);
274+
assert.lengthOf(shiftedEqual, 1);
275+
assert.lengthOf(
276+
viewMenu.submenu.filter((item) => item.accelerator === "CmdOrCtrl+numadd"),
277+
1,
278+
);
279+
const zoomIn = shiftedEqual[0];
272280
assert.isDefined(zoomIn);
273-
assert.equal(zoomIn.accelerator, "CmdOrCtrl+=");
281+
assert.isFalse(zoomIn.visible);
274282
if (typeof zoomIn.click !== "function") {
275283
throw new Error("Expected Zoom In menu item to have a click handler.");
276284
}

‎apps/desktop/src/window/DesktopApplicationMenu.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ export const make = Effect.gen(function* () {
263263
visible: false,
264264
click: zoomClick("in"),
265265
},
266+
...(environment.platform === "darwin"
267+
? [
268+
{
269+
label: "Zoom In",
270+
accelerator: "CmdOrCtrl+Shift+=",
271+
visible: false,
272+
click: zoomClick("in"),
273+
},
274+
]
275+
: []),
266276
{ label: "Zoom Out", accelerator: "CmdOrCtrl+-", click: zoomClick("out") },
267277
// The numeric keypad sends its own key codes, so the number-row
268278
// accelerators above never match it.

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,10 @@ describe("DesktopWindow", () => {
774774
// Chromium hands the main window's zoom level down to embedded preview
775775
// guests, so every app zoom has to put the preview browser back at its own
776776
// zoom or zooming the UI drags the previewed page with it.
777-
it.effect("restores the preview browser's own zoom after zooming the app", () =>
777+
it.effect("zooms main with a focused popup and reapplies preview zoom", () =>
778778
Effect.gen(function* () {
779779
const fakeWindow = makeFakeBrowserWindow();
780+
const popup = makeFakeBrowserWindow();
780781
const createCount = yield* Ref.make(0);
781782
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
782783
const previewZoomReapplies: number[] = [];
@@ -785,6 +786,7 @@ describe("DesktopWindow", () => {
785786
createCount,
786787
mainWindow,
787788
previewZoomReapplies,
789+
focusedWindow: popup.window,
788790
});
789791

790792
yield* Effect.gen(function* () {
@@ -801,6 +803,7 @@ describe("DesktopWindow", () => {
801803
[-0.5, -1, -0.5, 0],
802804
);
803805
assert.deepEqual(previewZoomReapplies, [-0.5, -1, -0.5, 0]);
806+
assert.equal(popup.setZoomLevel.mock.calls.length, 0);
804807
}).pipe(Effect.provide(layer));
805808
}),
806809
);

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ export const make = Effect.gen(function* () {
10261026
}),
10271027
zoomMain: Effect.fn("desktop.window.zoomMain")(function* (direction) {
10281028
yield* Effect.annotateCurrentSpan({ direction });
1029-
const window = yield* focusedMainWindow;
1029+
const window = yield* electronWindow.main;
10301030
if (Option.isNone(window) || window.value.isDestroyed()) {
10311031
return;
10321032
}

0 commit comments

Comments
 (0)