Skip to content

Commit 4c8e7fd

Browse files
committed
fix: to microsoft#182266, Corrected Webview hasFocus check
1 parent b3b84b5 commit 4c8e7fd

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/vs/workbench/browser/layout.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { AuxiliaryBarPart } from 'vs/workbench/browser/parts/auxiliarybar/auxili
4949
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
5050
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
5151
import { mainWindow } from 'vs/base/browser/window';
52+
import { IPaneComposite } from 'vs/workbench/common/panecomposite';
5253

5354
//#region Layout Implementation
5455

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

1086-
hasFocus(part: Parts): boolean {
1087+
hasFocus(part: Parts, viewContainerId?: string): boolean {
10871088
const container = this.getContainer(getActiveWindow(), part);
10881089
if (!container) {
10891090
return false;
10901091
}
10911092

1092-
const activeElement = container.ownerDocument.activeElement;
1093+
const activeElement = document.activeElement;
10931094
if (!activeElement) {
10941095
return false;
10951096
}
10961097

1097-
return isAncestorUsingFlowTo(activeElement, container);
1098+
const activePanel = this.getFocusWebviewPart(part);
1099+
if (viewContainerId && viewContainerId === activePanel?.getId()) {
1100+
return true;
1101+
}
1102+
1103+
return !!container && isAncestorUsingFlowTo(activeElement, container);
1104+
}
1105+
1106+
getFocusWebviewPart(part: Parts): IPaneComposite | undefined {
1107+
let focusPart: IPaneComposite | undefined;
1108+
// only these two part will combine webview view container
1109+
switch (part) {
1110+
case Parts.PANEL_PART: {
1111+
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
1112+
break;
1113+
}
1114+
case Parts.SIDEBAR_PART: {
1115+
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar);
1116+
break;
1117+
}
1118+
case Parts.AUXILIARYBAR_PART: {
1119+
focusPart = this.paneCompositeService.getActivePaneComposite(ViewContainerLocation.AuxiliaryBar);
1120+
break;
1121+
}
1122+
}
1123+
return focusPart;
10981124
}
10991125

11001126
focusPart(part: MULTI_WINDOW_PARTS, targetWindow: Window): void;
@@ -1104,7 +1130,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
11041130
if (container) {
11051131
focusWindow(container);
11061132
}
1107-
11081133
switch (part) {
11091134
case Parts.EDITOR_PART:
11101135
this.editorGroupService.getPart(container).activeGroup.focus();

src/vs/workbench/browser/parts/views/viewsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,15 @@ export class ViewsService extends Disposable implements IViewsService {
393393
case ViewContainerLocation.AuxiliaryBar:
394394
case ViewContainerLocation.Sidebar: {
395395
const part = viewContainerLocation === ViewContainerLocation.Sidebar ? Parts.SIDEBAR_PART : Parts.AUXILIARYBAR_PART;
396-
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(part)) {
396+
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(part, viewContainer.id)) {
397397
await viewsService.openViewContainer(viewContainer.id, true);
398398
} else {
399399
editorGroupService.activeGroup.focus();
400400
}
401401
break;
402402
}
403403
case ViewContainerLocation.Panel:
404-
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(Parts.PANEL_PART)) {
404+
if (!viewsService.isViewContainerVisible(viewContainer.id) || !layoutService.hasFocus(Parts.PANEL_PART, viewContainer.id)) {
405405
await viewsService.openViewContainer(viewContainer.id, true);
406406
} else {
407407
viewsService.closeViewContainer(viewContainer.id);

src/vs/workbench/services/layout/browser/layoutService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export interface IWorkbenchLayoutService extends ILayoutService {
164164
/**
165165
* Returns whether the given part has the keyboard focus or not.
166166
*/
167-
hasFocus(part: Parts): boolean;
167+
hasFocus(part: Parts, viewContainerId?: string): boolean;
168168

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

0 commit comments

Comments
 (0)