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

change panel toggle logic (for #19400) #59019

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/vs/workbench/browser/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { IPanel } from 'vs/workbench/common/panel';
import { Composite, CompositeDescriptor, CompositeRegistry } from 'vs/workbench/browser/composite';
import { Action } from 'vs/base/common/actions';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
import { isAncestor } from 'vs/base/browser/dom';

export abstract class Panel extends Composite implements IPanel { }

Expand Down Expand Up @@ -76,17 +77,18 @@ export abstract class TogglePanelAction extends Action {
}

run(): TPromise<any> {
if (this.isPanelShowing()) {
if (this.isPanelFocused()) {
return this.partService.setPanelHidden(true);
}

return this.panelService.openPanel(this.panelId, true);
}

private isPanelShowing(): boolean {
const panel = this.panelService.getActivePanel();
private isPanelFocused(): boolean {
const activePanel = this.panelService.getActivePanel();
const activeElement = document.activeElement;

return panel && panel.getId() === this.panelId;
return activePanel && activeElement && isAncestor(activeElement, this.partService.getContainer(Parts.PANEL_PART));
}
}

Expand Down