Skip to content

Commit 799bbd8

Browse files
committed
Fixes showing hidden grouped views
1 parent a96e1e4 commit 799bbd8

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/views/scmGroupedView.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class ScmGroupedView implements Disposable {
5757
}
5858

5959
private onReady() {
60-
this._view = this.setView(this.views.lastSelectedScmGroupedView!);
60+
// Since we don't want the view to open on every load, prevent revealing it
61+
this._view = this.setView(this.views.lastSelectedScmGroupedView!, { focus: false, preventReveal: true });
6162
}
6263

6364
get view(): TreeViewByType[GroupableTreeViewTypes] | undefined {
@@ -126,13 +127,18 @@ export class ScmGroupedView implements Disposable {
126127
}
127128
}
128129

129-
setView<T extends GroupableTreeViewTypes>(type: T, focus?: boolean): TreeViewByType[T] {
130+
setView<T extends GroupableTreeViewTypes>(
131+
type: T,
132+
options?: { focus?: boolean; preventReveal?: boolean },
133+
): TreeViewByType[T] {
130134
if (!this.views.scmGroupedViews?.has(type)) {
131135
type = this.views.scmGroupedViews?.size ? (first(this.views.scmGroupedViews) as T) : undefined!;
132136
}
133137

134138
void setContext('gitlens:views:scm:grouped:loading', true);
135139
clearTimeout(this._clearLoadingTimer);
140+
141+
const wasVisible = this._tree?.visible ?? false;
136142
this.resetTree();
137143

138144
this._loaded?.cancel();
@@ -143,8 +149,8 @@ export class ScmGroupedView implements Disposable {
143149

144150
const view = this._view;
145151
if (view != null) {
146-
if (!view.visible) {
147-
await view.show({ preserveFocus: !focus });
152+
if (!options?.preventReveal && !view.visible) {
153+
await view.show({ preserveFocus: !options?.focus });
148154
}
149155

150156
let selection = this._lastSelectedByView.get(type);
@@ -154,19 +160,23 @@ export class ScmGroupedView implements Disposable {
154160
selection = { node: view.selection[0], parents: undefined, expanded: false };
155161
}
156162
if (selection == null) {
157-
if (focus) {
163+
if (options?.focus) {
158164
await view.show({ preserveFocus: false });
159165
}
160166
return;
161167
}
162168

163169
const { node, parents, expanded } = selection;
164170
if (parents == null) {
165-
await view.revealDeep(node, { expand: expanded, focus: focus ?? false, select: true });
171+
await view.revealDeep(node, {
172+
expand: expanded,
173+
focus: options?.focus ?? false,
174+
select: true,
175+
});
166176
} else {
167177
await view.revealDeep(node, parents, {
168178
expand: expanded,
169-
focus: focus ?? false,
179+
focus: options?.focus ?? false,
170180
select: true,
171181
});
172182
}
@@ -192,6 +202,10 @@ export class ScmGroupedView implements Disposable {
192202

193203
this.views.lastSelectedScmGroupedView = type;
194204

205+
if (!options?.preventReveal && !wasVisible) {
206+
void this._view.show({ preserveFocus: !options?.focus });
207+
}
208+
195209
return this._view as TreeViewByType[T];
196210
}
197211

src/views/viewBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ export abstract class ViewBase<
10081008
try {
10091009
const command = getViewFocusCommand(this.grouped ? 'gitlens.views.scm.grouped' : this.id);
10101010
// If we haven't been initialized, the focus command will show the view, but won't focus it, so wait until it's initialized and then focus again
1011-
if (this.initialized.pending) {
1011+
if (!options?.preserveFocus && this.initialized.pending) {
10121012
void executeCoreCommand(command, options);
10131013
await this.initialized.promise;
10141014
}

src/views/views.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export class Views implements Disposable {
501501
private async setScmGroupedView<T extends GroupableTreeViewTypes>(type: T, focus?: boolean) {
502502
if (this._scmGroupedView != null) {
503503
await this._scmGroupedView.clearView(type);
504-
return this._scmGroupedView.setView(type, focus);
504+
return this._scmGroupedView.setView(type, { focus: focus });
505505
}
506506

507507
if (!this.scmGroupedViews?.has(type)) {

0 commit comments

Comments
 (0)