Fix shortcuts double-emitting from browser on Mac#306198
Merged
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jrualesMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts keyboard event forwarding from the Integrated Browser (BrowserView) preload script to avoid shortcut handling being triggered both by the embedded page/browser and by VS Code—particularly on macOS.
Changes:
- Refines which keydown events are forwarded to the workbench (modifier-based + “non-editing” keys).
- Adds special-casing to keep common clipboard/editing shortcuts handled natively by the browser.
- Prevents/stops propagation for forwarded events to avoid native handling (and potential double-execution).
Comments suppressed due to low confidence (3)
src/vs/platform/browserView/electron-browser/preload-browserView.ts:61
- The Alt-key filtering only excludes
altKeywhenctrlKey/metaKeyare false. On Windows/Linux keyboard layouts, AltGr is commonly reported as Ctrl+Alt; with the current logic those keydowns will be forwarded andpreventDefault()will run, likely breaking typing of AltGr characters in page inputs. Consider detecting AltGraph viaevent.getModifierState?.('AltGraph')(or a similar AltGr heuristic) and treating it like plain character input (do not forward / do not preventDefault).
// Alt+Key special character handling (Alt + Numpad keys on Windows/Linux, Alt + any key on Mac)
if (event.altKey && !event.ctrlKey && !event.metaKey) {
if (isMac || /^Numpad\d+$/.test(event.code)) {
return;
}
}
src/vs/platform/browserView/electron-browser/preload-browserView.ts:77
- The allowlist for “native shortcuts” is currently limited to a/c/v/x/z (+shift variants) and redo on Win/Linux. This means common text-editing/navigation shortcuts like Cmd/Ctrl+Arrow (home/end/word navigation), Cmd/Ctrl+Backspace/Delete, etc. will now be forwarded and
preventDefault()'d, which can break expected editing behavior in web page inputs/contenteditable elements. Consider skipping forwarding/preventDefault when the event target is editable, or expand the native-shortcut allowlist to include these editing/navigation combinations.
// Allow native shortcuts (copy, paste, cut, undo, redo, select all) to be handled by the browser
const ctrlCmd = isMac ? event.metaKey : event.ctrlKey;
if (ctrlCmd && !event.altKey) {
const key = event.key.toLowerCase();
if (!event.shiftKey && (key === 'a' || key === 'c' || key === 'v' || key === 'x' || key === 'z')) {
return;
}
if (event.shiftKey && (key === 'v' || key === 'z')) {
return;
}
// Ctrl+Y is redo on Windows/Linux
if (!event.shiftKey && key === 'y' && !isMac) {
return;
}
}
src/vs/platform/browserView/electron-browser/preload-browserView.ts:55
isMacdetection usesnavigator.platform, which is deprecated and can be influenced by the page environment. Since this preload already has Node/Electron access, preferprocess.platform === 'darwin'for a stable platform check.
const isMac = navigator.platform.indexOf('Mac') >= 0;
rebornix
approved these changes
Mar 30, 2026
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.
No description provided.