Skip to content

Fix webview focus issues that prevent cut/copy/paste when opening files with a quick pick #116899

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

Merged
merged 5 commits into from
Feb 19, 2021

Conversation

tspence
Copy link
Contributor

@tspence tspence commented Feb 18, 2021

This PR fixes #116897.

When you use a full-screen webview, and then change focus away from it with a quick-pick (e.g. Cmd+P or Ctrl+P to open the file access quick pick), two different focus events happen rapidly:

  • The quick pick tells the editor to open a new file, and
  • The quick pick closes, which sends a focus message to the host telling it to return the focus back to the previously focused element.

Because webviews also have a special _focused flag, and because that flag is used to determine whether a webview should steal Cut/Copy/Paste commands, users can experience that cut/copy/paste no longer work in a second quickpick opened after the webview thinks it has focus.

This change prevents the webview from thinking it has focus when something else has taken place prior to the quick pick's close event.

tspence and others added 5 commits January 25, 2021 09:52
A webview can be sent a delayed focus change.  These delayed focus changes can sometimes be received after many things have happened to focus.

An example is issue microsoft#116897 - if you use a quick pick to jump away from a webview, the webview may sometimes receive notifications that it has regained the focus after the quick pick closes.

This change prevents the webview from incorrectly thinking it has obtained focus.
@tspence tspence changed the title Webview focus Fix webview focus issues that prevent cut/copy/paste when opening files with a quick pick Feb 18, 2021
@tspence
Copy link
Contributor Author

tspence commented Feb 19, 2021

This may also be related to #109874 and #114325.

I note that these two issues also include screenshots that demonstrate a webview in focus when the user reported the problem with a quick pick.

@mjbvz mjbvz added this to the February 2021 milestone Feb 19, 2021
@mjbvz mjbvz merged commit 5ba8f6e into microsoft:main Feb 19, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 19, 2021

Thanks! Let's test this in insiders and see if it causes any issues. Currently on track for VS Code 1.54

mjbvz added a commit that referenced this pull request Feb 25, 2021
…ning files with a quick pick (#116899)"

This reverts commit 5ba8f6e.

Fixes #117595

Looks like the first time this is called, document.activeElement is still `<body>`
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 25, 2021

I had to revert this due to a regression (#117595):

  1. Open a md file
  2. Open the preview to the side
  3. Try using arrow keys to scroll the preview

The arrow keys no longer work since the webview is not focused.

@tspence Please look into revisiting when you have a chance

@tspence
Copy link
Contributor Author

tspence commented Feb 25, 2021

Thanks for the feedback! I'll see if I can investigate an alternative approach to solve this issue.

The root problem for me seemed to be:

  1. Focus is on a webview
  2. Open quick pick file selector
  3. Choose one of the available files
  4. Simultaneously: Quick pick closes and returns focus to webview; && quick pick selects a file and notifies VS Code to open and focus it.

In some cases when the webview is busy, it gets the notification to obtain focus after the quick pick has opened the new file. This seemed to affect us at FB more often because one of our webviews does lots of source control work.

A better fix might be to delay the "launch new file" action until after the quick pick has closed, or to make the quick pick not return focus to the previous webview if it took some action.

I'll consider what I can do and test something out using the #117595 issue you linked before resubmitting.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webviews can prevent keyboard shortcuts from working in quick picks
2 participants