Skip to content
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

[Fix] Webview is not focused after cancelling quick open widget #8137

Merged
merged 1 commit into from
Jul 6, 2020

Conversation

shahar-h
Copy link
Contributor

@shahar-h shahar-h commented Jul 5, 2020

Signed-off-by: Shahar Harari [email protected]

What it does

Fixes the following issue:
When quick open widget is triggered while some webview is focused, cancelling the quick open widget doesn't bring focus back to webview. As a result, when triggering quick open widget again by pressing F1 a new browser tab is opened instead.

Root cause of this issue:
When closing quick open widget by pressing escape or changing focus, focus is set to the previousFocusElement:

onCancel: () => {
if (this.previousActiveElement instanceof HTMLElement) {
this.previousActiveElement.focus({ preventScroll: true });
}

previuosFocusElement is webview main frame(The one with webview class) in case webview was focused before triggering the quick open widget, so it's being focused, but since keydown handler is registered on the inner frame (The one with active-frame id) keydown events will stop work from this point until the inner frame is focused manually:
newFrame.contentWindow.addEventListener('keydown', handleInnerKeydown);

My solution is register to focus events on main webview node and send focus message to inner frame in this case.

How to test

  1. Install GitLens VS Code extension.
  2. Open Git Lens welcome page by pressing F1 and choose GitLens: Welcome from the command palette.
  3. Focus Git Lens welcome page.
  4. Press F1 and then press Esc key or mouse left click outside the quick open widget.
  5. Press F1 again - the quick open widget should be opened again. Without the fix a new browser tab will be opened instead.

Before:
before

After:
after

Review checklist

Reminder for reviewers

@akosyakov akosyakov added the webviews issues related to webviews label Jul 6, 2020
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice solution, thank you!

@akosyakov akosyakov merged commit 5818d50 into eclipse-theia:master Jul 6, 2020
@shahar-h shahar-h deleted the focus-webview branch July 6, 2020 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
webviews issues related to webviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants