Repository navigation
Fix random focus lost issues on CTRL+1/2 for a webview - #111676
Conversation
| // Clear the existing focus first if not already on the webview. | ||
| // This is required because the next part where we set the focus is async. | ||
| if (document.activeElement && document.activeElement instanceof HTMLElement) { | ||
| if (document.activeElement && document.activeElement instanceof HTMLElement && document.activeElement?.tagName !== 'WEBVIEW') { |
There was a problem hiding this comment.
nit pick: null propagation on the last check if not required as documet.activeElement is guaranteed to exist, due to first check
There was a problem hiding this comment.
Good point. Will fix
|
Thanks for looking into this! Can you make sure that this does not regress other cases, specifically:
I believe the existing code was written this way to handle those cases and I want to make sure we don't break them again Make sure to test with both custom title bars enabled and with them disabled (use the |
|
Thanks Matt Bierner (@mjbvz) . #75209 I had originally tested (well because my original implementation broke this bug) so that one I can say it still works. If I go to the settings icon while a webview has focus, the file theme picker will show up. #101553 I think it still works? Does this gif show it working (meaning am I following the repro steps)? |
|
Rich Chiodo (@rchiodo) The looks correct to me. Thanks for testing! I've scheduled this for the December/January vscode iteration. This should give us lots of time to test this in insiders too |

This PR fixes #97992
What I believe is happening (after adding a bunch of logging) is that the blur here:
vscode/src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts
Line 237 in 4d9277a
is also async when sent to a webview.
This can cause the blur to fire randomly, sometimes after the focus trigger has fired (but also sometimes before, when it works).
This should resolve the problem we've been having with microsoft/vscode-jupyter#1293 (or at least make it possible for us to handle focus correctly)
/cc Matt Bierner (@mjbvz)