From b0ef90f5ff42835ecc8f031190dd3d46a8dd8125 Mon Sep 17 00:00:00 2001 From: Andrew Polk Date: Mon, 9 Feb 2026 14:28:15 -0700 Subject: [PATCH] Fix BL-15383 prevent Ctrl+P print dialog https://issues.bloomlibrary.org/youtrack/issue/BL-15383 --- src/BloomExe/WebView2Browser.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/BloomExe/WebView2Browser.cs b/src/BloomExe/WebView2Browser.cs index 3c428a67d2a2..7a586fafc225 100644 --- a/src/BloomExe/WebView2Browser.cs +++ b/src/BloomExe/WebView2Browser.cs @@ -176,6 +176,27 @@ CoreWebView2NavigationStartingEventArgs args //}; _webview.CoreWebView2.ContextMenuRequested += ContextMenuRequested; + // BL-15383: Prevent Ctrl+P from opening the WebView2 print dialog. + // Bloom has its own printing workflows; the embedded browser print UI is confusing. + _webview.CoreWebView2Controller.AcceleratorKeyPressed += (o, e) => + { + if ( + e.KeyEventKind == CoreWebView2KeyEventKind.KeyDown + || e.KeyEventKind == CoreWebView2KeyEventKind.SystemKeyDown + ) + { + if ( + e.VirtualKey == (int)Keys.P + && (e.KeyModifiers & CoreWebView2KeyModifiers.Control) != 0 + && (e.KeyModifiers & CoreWebView2KeyModifiers.Shift) == 0 + && (e.KeyModifiers & CoreWebView2KeyModifiers.Alt) == 0 + ) + { + e.Handled = true; + } + } + }; + // This is only really needed for the print tab. But it is harmless elsewhere. // It removes some unwanted controls from the toolbar that WebView2 inserts when // previewing a PDF file.