提交 bd0a576d 编写于 作者: S Sandeep Somavarapu

Fix #41377

上级 a08d1550
......@@ -134,7 +134,7 @@ interface IViewletPanelItem {
export class PanelViewlet extends Viewlet {
protected lastFocusedPanel: ViewletPanel | undefined;
private lastFocusedPanel: ViewletPanel | undefined;
private panelItems: IViewletPanelItem[] = [];
private panelview: PanelView;
......@@ -195,7 +195,11 @@ export class PanelViewlet extends Viewlet {
if (this.lastFocusedPanel) {
this.lastFocusedPanel.focus();
} else if (this.panelItems.length > 0) {
this.panelItems[0].panel.focus();
for (const { panel } of this.panelItems) {
if (panel.isExpanded()) {
panel.focus();
}
}
}
}
......@@ -213,8 +217,13 @@ export class PanelViewlet extends Viewlet {
addPanel(panel: ViewletPanel, size: number, index = this.panelItems.length - 1): void {
const disposables: IDisposable[] = [];
const onDidFocus = panel.onDidFocus(() => this.lastFocusedPanel = panel, null, disposables);
const onDidChange = panel.onDidChange(() => {
if (panel === this.lastFocusedPanel && !panel.isExpanded()) {
this.lastFocusedPanel = undefined;
}
}, null, disposables);
const styler = attachPanelStyler(panel, this.themeService);
const disposable = combinedDisposable([onDidFocus, styler]);
const disposable = combinedDisposable([onDidFocus, styler, onDidChange]);
const panelItem: IViewletPanelItem = { panel, disposable };
this.panelItems.splice(index, 0, panelItem);
......
......@@ -347,16 +347,23 @@ export class ViewsViewlet extends PanelViewlet {
super.shutdown();
}
toggleViewVisibility(id: string, visible?: boolean): void {
toggleViewVisibility(id: string): void {
const view = this.getView(id);
let viewState = this.viewsStates.get(id);
if (!viewState || (visible === true && view) || (visible === false && !view)) {
if (!viewState) {
return;
}
viewState.isHidden = !!view;
this.updateViews();
this.updateViews()
.then(() => {
if (!viewState.isHidden) {
this.getView(id).focus();
} else {
this.focus();
}
});
}
private onViewsRegistered(views: IViewDescriptor[]): void {
......
......@@ -226,67 +226,6 @@ export class ExplorerViewlet extends PersistentViewsViewlet implements IExplorer
return super.setVisible(visible);
}
public focus(): void {
const hasOpenedEditors = !!this.editorGroupService.getStacksModel().activeGroup;
let openEditorsView = this.getOpenEditorsView();
if (this.lastFocusedPanel && this.lastFocusedPanel.isExpanded() && this.hasSelectionOrFocus(this.lastFocusedPanel as ViewsViewletPanel)) {
if (this.lastFocusedPanel !== openEditorsView || hasOpenedEditors) {
this.lastFocusedPanel.focus();
return;
}
}
if (this.hasSelectionOrFocus(openEditorsView) && hasOpenedEditors) {
return openEditorsView.focus();
}
let explorerView = this.getExplorerView();
if (this.hasSelectionOrFocus(explorerView)) {
return explorerView.focus();
}
if (openEditorsView && openEditorsView.isExpanded() && hasOpenedEditors) {
return openEditorsView.focus(); // we have entries in the opened editors view to focus on
}
if (explorerView && explorerView.isExpanded()) {
return explorerView.focus();
}
let emptyView = this.getEmptyView();
if (emptyView && emptyView.isExpanded()) {
return emptyView.focusBody();
}
super.focus();
}
private hasSelectionOrFocus(view: ViewsViewletPanel): boolean {
if (!view) {
return false;
}
if (!view.isExpanded()) {
return false;
}
if (view instanceof ExplorerView) {
const viewer = view.getViewer();
if (!viewer) {
return false;
}
return !!viewer.getFocus() || (viewer.getSelection() && viewer.getSelection().length > 0);
}
if (view instanceof OpenEditorsView && !!view.getList()) {
return view.getList().isDOMFocused();
}
return false;
}
public getActionRunner(): IActionRunner {
if (!this.actionRunner) {
this.actionRunner = new ActionRunner(this.viewletState);
......
......@@ -216,6 +216,11 @@ export class OpenEditorsView extends ViewsViewletPanel {
});
}
public focus(): void {
this.list.domFocus();
super.focus();
}
public getList(): WorkbenchList<OpenEditor | IEditorGroup> {
return this.list;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册