Skip to content

Register alternative keyboard shortcuts for zooming in - #2426

Open
robertobandini wants to merge 2 commits into
mainfrom
claude/issue-1848-20260804-1540
Open

robertobandini wants to merge 2 commits into
mainfrom
claude/issue-1848-20260804-1540

Conversation

@robertobandini

Copy link
Copy Markdown
Member

Zoom In could not be triggered from the keyboard on layouts where + is not the shifted =.

Root cause

Electron's zoomIn role defaults to the CommandOrControl+Plus accelerator. In Electron 42.7.1 (shell/common/keyboard_util.cc) the plus token maps to {VKEY_OEM_PLUS, '+'} with a shifted character, so accelerator_util.cc adds EF_SHIFT_DOWN: the accelerator is literally Ctrl + Shift + VKEY_OEM_PLUS. That only matches keyboards where + is the shifted = (US/UK). On Italian, German, Nordic and similar layouts the key Windows reports as VK_OEM_PLUS is the dedicated + key, pressed without Shift, so the combination never matches; the numeric keypad + (VKEY_ADD) never matches on any layout. Zoom Out is unaffected because CommandOrControl+- needs no Shift. Clicking the menu item bypasses accelerator matching, which is why the mouse path works.

Fix

An Electron MenuItem holds a single accelerator, so the alternatives are registered as hidden menu items: GenerateAcceleratorTable walks the menu model without looking at visibility (it only honours registerAccelerator, which is true for the zoom roles), so a visible: false item keeps its shortcut without adding a duplicate entry to the View menu.

  • OsActionMenuItem gains an optional visible flag (MayBeHiddenFromMenu), passed through to the Electron template
  • Zoom In gains CommandOrControl+= (the unshifted VKEY_OEM_PLUS: + on IT/DE keyboards, = on US ones, also the common Chrome-style shortcut) and CommandOrControl+numadd
  • Zoom Out gains CommandOrControl+numsub
  • regression test zoom-keyboard-shortcuts.test.ts (one visible item per direction, alias accelerators present), snapshot and DI registration updated

Applies to v2 (main); the same three source files are byte-identical on v1, so a backport is a clean cherry-pick (the new test needs porting from vitest to jest).

Verification

Run locally on macOS (x64) against this branch, replicating the PR workflows:

  • unit tests: 352 files / 3591 tests passed (full suite), including the new test and the win32/darwin/linux menu snapshots
  • type:check, build:di (no drift), knip:check, trunk check --all: clean
  • packaged app (electron-builder --macos dir) + integration tests: passed (KinD-dependent tests skipped as in CI)

Not yet verified: the actual key presses on Windows. The unit test only proves the Electron menu template carries the accelerators; the matching happens in native code and depends on the keyboard layout. Someone with Windows and an Italian/German layout should check Ctrl + + (main key), Ctrl + keypad +, Ctrl + keypad -, and on a US layout that Ctrl+Shift+= still works and Ctrl+= now works too. If nobody gets to it, I will do it myself ASAP.

Fixes #1848

Generated with Claude Code

| Model: claude-opus-5 (analysis and fix), claude-fable-5 (review and verification)

github-actions Bot and others added 2 commits August 4, 2026 15:47
The "zoomIn" Electron role defaults to the "CommandOrControl+Plus"
accelerator, which Electron resolves to Control, Shift and the key that
Windows maps to VKEY_OEM_PLUS. On layouts where "+" is not the shifted
"=" (German, Italian and others) that combination cannot be typed, so
Zoom In never fires from the keyboard while Zoom Out, whose accelerator
needs no Shift, keeps working.

Register the missing accelerators as hidden menu items: hidden items are
still part of the menu, so Electron registers their accelerators without
showing duplicate entries. Zoom In gains "CommandOrControl+=" and the
plus of the numeric keypad, Zoom Out the keypad minus.

Fixes #1848

Co-authored-by: Roberto Bandini <11294865+robertobandini@users.noreply.github.com>
@robertobandini

Copy link
Copy Markdown
Member Author

I built this branch on Windows (portable Node 24.18.0, no elevated access needed) and tested the packaged app personally with the Italian QWERTY keyboard layout: I confirm the fix works — Zoom In is now triggered correctly from the keyboard.

This covers the "not yet verified on Windows" part of the PR description.

As per our usual practice, I'm requesting a review from @dex4er before merging.

@robertobandini
robertobandini requested a review from dex4er August 24, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoom In Keyboard Shortcut (Ctrl + +) Not Working

1 participant