Skip to content

Commit

Permalink
fix: to microsoft#182266, Corrected Webview hasFocus check
Browse files Browse the repository at this point in the history
  • Loading branch information
yiliang114 committed Nov 28, 2023
1 parent b3b84b5 commit 4c8e7fd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
33 changes: 29 additions & 4 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { AuxiliaryBarPart } from 'vs/workbench/browser/parts/auxiliarybar/auxili
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
import { mainWindow } from 'vs/base/browser/window';
import { IPaneComposite } from 'vs/workbench/common/panecomposite';

//#region Layout Implementation

Expand Down Expand Up @@ -1083,18 +1084,43 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this._register(delegate.onDidChangeNotificationsVisibility(visible => this._onDidChangeNotificationsVisibility.fire(visible)));
}

hasFocus(part: Parts): boolean {
hasFocus(part: Parts, viewContainerId?: string): boolean {
const container = this.getContainer(getActiveWindow(), part);
if (!container) {
return false;
}

const activeElement = container.ownerDocument.activeElement;
const activeElement = document.activeElement;
if (!activeElement) {
return false;
}

return isAncestorUsingFlowTo(activeElement, container);
const activePanel = this.getFocusWebviewPart(part);
if (viewContainerId && viewContainerId === activePanel?.getId()) {
return true;
}

return !!container && isAncestorUsingFlowTo(activeElement, container);
}

getFocusWebviewPart(part: Parts): IPaneComposite | undefined {
let focusPart: IPaneComposite | undefined;
// only these two part will combine webview view container
switch (part) {
case Parts.PANEL_PART: {
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
break;
}
case Parts.SIDEBAR_PART: {
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar);
break;
}
case Parts.AUXILIARYBAR_PART: {
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.AuxiliaryBar);
break;
}
}
return focusPart;
}

focusPart(part: MULTI_WINDOW_PARTS, targetWindow: Window): void;
Expand All @@ -1104,7 +1130,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
if (container) {
focusWindow(container);
}

switch (part) {
case Parts.EDITOR_PART:
this.editorGroupService.getPart(container).activeGroup.focus();
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/views/viewsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ export class ViewsService extends Disposable implements IViewsService {
case ViewContainerLocation.AuxiliaryBar:
case ViewContainerLocation.Sidebar: {
const part = viewContainerLocation === ViewContainerLocation.Sidebar ? Parts.SIDEBAR_PART : Parts.AUXILIARYBAR_PART;
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(part)) {
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(part, viewContainer.id)) {
await viewsService.openViewContainer(viewContainer.id, true);
} else {
editorGroupService.activeGroup.focus();
}
break;
}
case ViewContainerLocation.Panel:
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(Parts.PANEL_PART)) {
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(Parts.PANEL_PART, viewContainer.id)) {
await viewsService.openViewContainer(viewContainer.id, true);
} else {
viewsService.closeViewContainer(viewContainer.id);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/layout/browser/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface IWorkbenchLayoutService extends ILayoutService {
/**
* Returns whether the given part has the keyboard focus or not.
*/
hasFocus(part: Parts): boolean;
hasFocus(part: Parts, viewContainerId?: string): boolean;

/**
* Focuses the part in the target window. If the part is not visible this is a noop.
Expand Down

0 comments on commit 4c8e7fd

Please sign in to comment.