-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix: Rerouted the "close tab" action via event listener in WebView #18038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the "close tab" action shortcuts (Ctrl+W and Ctrl+F4) on the Release Notes page by implementing JavaScript keyboard event listeners in the WebView that communicate with the Files.App action system.
Changes:
- Added JavaScript keyboard event listener to capture close tab shortcuts within the WebView
- Refactored link-click handling to use structured JSON messages instead of plain strings
- Created a WebMessage DTO class to handle typed messages from JavaScript
- Added JavaScriptModifiers mapping in HotKey class to translate C# modifiers to JavaScript event properties
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/Files.App/Views/ReleaseNotesPage.xaml.cs | Added keyboard shortcut handling via JavaScript injection, refactored message handlers to use typed WebMessage objects, and added key normalization helper |
| src/Files.App/Data/Messages/WebMessage.cs | New DTO class for deserializing JSON messages from WebView JavaScript |
| src/Files.App/Data/Commands/HotKey/HotKey.cs | Added JavaScriptModifiers dictionary to map KeyModifiers to JavaScript event property names |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No idea why the tests are failing |
The tests passed after I reran them 🎉 Does this also enable other keyboard shortcuts? (I haven't reviewed or tested these changes yet) |
No, that would require additional work. |
|
The same issue preventing |
|
I can do that, but it will require additional work. |
|
If we can figure out why the shortcuts aren't already detected, that would be ideal and would avoid a lot of extra work. It might even help us with the touchpad scrolling issue. |
|
I don't understand enough about webview2 in winappsdk to figure out why that happens unfortunately |
| } | ||
| }); | ||
| window.addEventListener('keydown', function(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an event listener seems to be the simplest workaround. I wonder if we can then reroute the event to MainPage and let it handle the shortcut from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further research, it looks like enabling AllowHostInputProcessing might be a better approach to take.
Resolved / Related Issues
Steps used to test these changes
This PR implements the "close current tab" action into the release notes page WebView by an injected event listener.