fix(shortcuts): wire Cmd/Ctrl +, - and 0 to webview zoom - #193
Open
alexwbend wants to merge 1 commit into
Open
Conversation
README documents Cmd/Ctrl+=, Cmd/Ctrl+- and Cmd/Ctrl+0 as zoom shortcuts, but nothing implemented them: zoom existed only as click handlers on the hamburger menu's - / + buttons. Electron's docs state that these shortcuts come from the zoomIn/zoomOut/resetZoom MenuItem roles, and menu.js defines the menu manually without them, so the keystrokes never reached the app. Add the three bindings to the shared shortcut registry so they gain a View menu group, a renderer keydown fallback for the Linux frameless setups where menu accelerators never arrive, and a remappable row in Settings > Shortcuts. The Electron roles are deliberately not used: they step zoomLevel on the focused webContents (the chrome, when the address bar has focus) rather than the active <webview>, they step by a different amount than the hamburger buttons, and their implicit accelerators would bypass the registry and could not be remapped. All three entry points now share one applyZoomFactor path so the zoom readout cannot drift from the webview's real factor. Closes solardev-xyz#88 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Wires
Cmd/Ctrl+=,Cmd/Ctrl+-andCmd/Ctrl+0to the active webview's zoom, closing #88. The bindings go into the shared shortcut registry, so they get a View menu group, a renderer keydown fallback, and a remappable row in Settings > Shortcuts, exactly like every other binding in the app.All three entry points (the hamburger
-/+buttons, the new menu accelerators, and the keydown fallback) now run through oneapplyZoomFactorhelper inmenus.js, so the100%readout can no longer drift from the webview's real zoom factor.Why
README.mdlines 308 to 310 document these three shortcuts, but nothing implemented them. Before this change the only way to zoom was opening the hamburger menu and clicking the-/+buttons.I confirmed the gap rather than assuming it:
globalShortcut, nobefore-input-event, and no keydown branch for=,-or0anywhere insrc/.menu.jsand omits those roles, so the shortcuts were switched off.Why not just add Electron's zoom roles
Adding
{ role: 'zoomIn' }and friends would be a three line change, but it would be wrong here for three reasons:zoomLevelon the focusedwebContents. Freedom's pages live in a<webview>guest while the chrome is the host renderer, so with focus in the address bar the roles would scale the browser UI rather than the page.zoomLevelis logarithmic and steps by 0.5, while the hamburger buttons stepzoomFactorlinearly by 0.1 within[0.25, 5]. Two entry points would move by different amounts and thezoom-levelreadout would not track the role driven path at all.src/shared/shortcuts.js, so it would not appear in Settings > Shortcuts and could not be remapped. That is the same class of collision thatmenu.test.jsalready guards against for explicit accelerators.Changes
src/shared/shortcuts.jspage.zoom*entries, categoryPage,context: 'both'src/renderer/lib/shortcuts.jssrc/main/menu.jspage:zoom-*src/main/preload.jsonZoomIn/onZoomOut/onZoomResetbridgessrc/renderer/lib/menus.jsapplyZoomFactorpath plus the IPC and keydown wiringsrc/main/menu.test.js,src/renderer/lib/menus.test.jstest-e2e/zoom.spec.jsHow to test
Manually:
npm start, load any page.Cmd/Ctrl+=a few times, thenCmd/Ctrl+-, thenCmd/Ctrl+0. The page zooms in 10% steps and resets to 100%.Automated:
Verification I ran
npm test: 158 suites, 3070 tests passing.npm run lint: clean.npx playwright test --project=harness test-e2e/zoom.spec.js: 4 passing, repeated three times for stability.CmdOrCtrl+=,CmdOrCtrl+-andCmdOrCtrl+0are accepted by the accelerator parser and survive aMenuround trip. A deliberately bogus accelerator throws, so the check is meaningful.Notes
settings-adblock.spec.jsfails on a clean checkout too because the adblock lists are not provisioned locally, which CI does since e368a40. One other spec (tez-unverified.spec.jsin the first run,permissions.spec.jsin the second) flaked differently each run and passes in isolation on both a clean tree and this branch, which matches the E2E flakiness tracked in flaky: e2e-address-bar-clipboard times out on Electron launch (required check, blocks merges) #180.src/main/preload.js,src/shared/shortcuts.jsandsrc/renderer/lib/menus.test.jsare already reported bynpm run format:checkonmain. The lines this PR adds are Prettier clean, and I deliberately did not run--writeon those files so the diff stays scoped.page:reloadandpage:hard-reloadwiring.page:*channels are not insrc/shared/ipc-channels.js, andpreload.jsdocuments that it cannot require that module from its sandboxed context. Happy to move them if you would rather centralise.Ctrl+Shift+=aliases. Each alias needs its own menu item in the current design, which would put visible duplicate rows in the View menu, so I left it at the three bindings the README promises. Users who want the numpad variants can remap in Settings.Cmd+P/Ctrl+Pon README line 311 is unwired in the same way: no menu item, no accelerator, no keydown handler, only the hamburger Print button. Happy to open a separate issue for it.windowfixture waits for the address bar, but that element is static markup inindex.htmland is present beforeinitMenus()andinitTabs()run.test-e2e/zoom.spec.jstherefore probes with Actual Size, which is idempotent, until the main to renderer path is demonstrably live before asserting anything.Closes #88
🤖 Generated with Claude Code