Skip to content

Commit 674042a

Browse files
committed
fix: Allow standard browser shortcuts (Ctrl+Z, etc.) to pass through to WebView2
Fixes #4723 The AcceleratorKeyCallback was posting all keyboard events to the main window, which interfered with WebView2's native handling of standard text editing shortcuts like Ctrl+Z (undo), Ctrl+Y (redo), Ctrl+X (cut), Ctrl+C (copy), Ctrl+V (paste), and Ctrl+A (select all). Changes: - Refactored AcceleratorKeyCallback to check keyboard state once - Added logic to detect standard Ctrl+key shortcuts (without Alt modifier) - These shortcuts now bypass posting to main window and are handled by WebView2 - Maintains existing Ctrl+Shift+F12 DevTools functionality - Preserves menu shortcut handling for all other key combinations
1 parent ba2c998 commit 674042a

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

v2/internal/frontend/desktop/windows/frontend.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,37 @@ func (f *Frontend) setupChromium() {
499499
chromium.WebResourceRequestedCallback = f.processRequest
500500
chromium.NavigationCompletedCallback = f.navigationCompleted
501501
chromium.AcceleratorKeyCallback = func(vkey uint) bool {
502-
if vkey == w32.VK_F12 && f.devtoolsEnabled {
503-
var keyState [256]byte
504-
if w32.GetKeyboardState(keyState[:]) {
505-
// Check if CTRL is pressed
506-
if keyState[w32.VK_CONTROL]&0x80 != 0 && keyState[w32.VK_SHIFT]&0x80 != 0 {
507-
chromium.OpenDevToolsWindow()
508-
return true
509-
}
510-
} else {
511-
f.logger.Error("Call to GetKeyboardState failed")
502+
var keyState [256]byte
503+
if !w32.GetKeyboardState(keyState[:]) {
504+
f.logger.Error("Call to GetKeyboardState failed")
505+
return false
506+
}
507+
508+
ctrlPressed := keyState[w32.VK_CONTROL]&0x80 != 0
509+
shiftPressed := keyState[w32.VK_SHIFT]&0x80 != 0
510+
altPressed := keyState[w32.VK_MENU]&0x80 != 0
511+
512+
// Handle Ctrl+Shift+F12 for DevTools
513+
if vkey == w32.VK_F12 && f.devtoolsEnabled && ctrlPressed && shiftPressed {
514+
chromium.OpenDevToolsWindow()
515+
return true
516+
}
517+
518+
// Allow standard browser/text editing shortcuts to pass through to WebView2
519+
// These should not be posted to the main window to avoid interference
520+
if ctrlPressed && !altPressed {
521+
switch vkey {
522+
case 0x5A, // Z - Undo
523+
0x59, // Y - Redo
524+
0x58, // X - Cut
525+
0x43, // C - Copy
526+
0x56, // V - Paste
527+
0x41: // A - Select All
528+
// Don't post these to main window, let WebView2 handle them
529+
return false
512530
}
513531
}
532+
514533
w32.PostMessage(f.mainWindow.Handle(), w32.WM_KEYDOWN, uintptr(vkey), 0)
515534
return false
516535
}

0 commit comments

Comments
 (0)