Skip to content

Commit a43f4bf

Browse files
committed
Moves view description to ViewBase
Fixes focus issue when attaching/detaching views
1 parent 8a9a0c2 commit a43f4bf

File tree

11 files changed

+42
-47
lines changed

11 files changed

+42
-47
lines changed

src/views/branchesView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class BranchesRepositoryNode extends RepositoryFolderNode<BranchesView, B
4848

4949
export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView, BranchesRepositoryNode> {
5050
async getChildren(): Promise<ViewNode[]> {
51-
this.view.description = this.getViewDescription();
51+
this.view.description = this.view.getViewDescription();
5252
this.view.message = undefined;
5353

5454
if (this.children == null) {
@@ -91,7 +91,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
9191
return [];
9292
}
9393

94-
this.view.description = this.getViewDescription(branches.values.length);
94+
this.view.description = this.view.getViewDescription(branches.values.length);
9595

9696
return child.getChildren();
9797
}

src/views/commitsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
121121
export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView, CommitsRepositoryNode> {
122122
async getChildren(): Promise<ViewNode[]> {
123123
if (this.children == null) {
124-
this.view.description = this.getViewDescription();
124+
this.view.description = this.view.getViewDescription();
125125
this.view.message = undefined;
126126

127127
const repositories = this.view.container.git.openRepositories;

src/views/contributorsView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ContributorsRepositoryNode extends RepositoryFolderNode<Contributor
5353

5454
export class ContributorsViewNode extends RepositoriesSubscribeableNode<ContributorsView, ContributorsRepositoryNode> {
5555
async getChildren(): Promise<ViewNode[]> {
56-
this.view.description = this.getViewDescription();
56+
this.view.description = this.view.getViewDescription();
5757
this.view.message = undefined;
5858

5959
if (this.children == null) {
@@ -106,7 +106,7 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
106106
return [];
107107
}
108108

109-
this.view.description = this.getViewDescription(children.length);
109+
this.view.description = this.view.getViewDescription(children.length);
110110

111111
return children;
112112
}

src/views/nodes/abstract/repositoriesSubscribeableNode.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ export abstract class RepositoriesSubscribeableNode<
3131
return szudzikPairing(this.view.container.git.etag, this.view.container.subscription.etag);
3232
}
3333

34-
protected getViewDescription(count?: number) {
35-
return `${this.view.grouped ? `${this.view.name.toLocaleLowerCase()} ` : ''}${
36-
count != null ? `(${count})` : ''
37-
}`;
38-
}
39-
4034
@debug()
4135
protected subscribe(): Disposable | Promise<Disposable> {
4236
return Disposable.from(

src/views/remotesView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class RemotesRepositoryNode extends RepositoryFolderNode<RemotesView, Rem
4848

4949
export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView, RemotesRepositoryNode> {
5050
async getChildren(): Promise<ViewNode[]> {
51-
this.view.description = this.getViewDescription();
51+
this.view.description = this.view.getViewDescription();
5252
this.view.message = undefined;
5353

5454
if (this.children == null) {
@@ -83,7 +83,7 @@ export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView,
8383
return [];
8484
}
8585

86-
this.view.description = this.getViewDescription(remotes.length);
86+
this.view.description = this.view.getViewDescription(remotes.length);
8787

8888
return child.getChildren();
8989
}

src/views/scmGroupedView.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export class ScmGroupedView implements Disposable {
3030

3131
executeCommand(`gitlens.views.${this._view.type}.refresh` as Commands);
3232
}),
33-
registerCommand('gitlens.views.scm.grouped.branches', () => this.setView('branches')),
34-
registerCommand('gitlens.views.scm.grouped.commits', () => this.setView('commits')),
35-
registerCommand('gitlens.views.scm.grouped.contributors', () => this.setView('contributors')),
36-
registerCommand('gitlens.views.scm.grouped.remotes', () => this.setView('remotes')),
37-
registerCommand('gitlens.views.scm.grouped.repositories', () => this.setView('repositories')),
38-
registerCommand('gitlens.views.scm.grouped.searchAndCompare', () => this.setView('searchAndCompare')),
39-
registerCommand('gitlens.views.scm.grouped.stashes', () => this.setView('stashes')),
40-
registerCommand('gitlens.views.scm.grouped.tags', () => this.setView('tags')),
41-
registerCommand('gitlens.views.scm.grouped.worktrees', () => this.setView('worktrees')),
33+
registerCommand('gitlens.views.scm.grouped.branches', () => this.setView('branches', true)),
34+
registerCommand('gitlens.views.scm.grouped.commits', () => this.setView('commits', true)),
35+
registerCommand('gitlens.views.scm.grouped.contributors', () => this.setView('contributors', true)),
36+
registerCommand('gitlens.views.scm.grouped.remotes', () => this.setView('remotes', true)),
37+
registerCommand('gitlens.views.scm.grouped.repositories', () => this.setView('repositories', true)),
38+
registerCommand('gitlens.views.scm.grouped.searchAndCompare', () => this.setView('searchAndCompare', true)),
39+
registerCommand('gitlens.views.scm.grouped.stashes', () => this.setView('stashes', true)),
40+
registerCommand('gitlens.views.scm.grouped.tags', () => this.setView('tags', true)),
41+
registerCommand('gitlens.views.scm.grouped.worktrees', () => this.setView('worktrees', true)),
4242
);
4343

4444
this._view = this.setView(this.views.lastSelectedScmGroupedView!);
@@ -49,7 +49,7 @@ export class ScmGroupedView implements Disposable {
4949
this._view?.dispose();
5050
}
5151

52-
setView<T extends GroupableTreeViewTypes>(type: T): TreeViewByType[T] {
52+
setView<T extends GroupableTreeViewTypes>(type: T, focus?: boolean): TreeViewByType[T] {
5353
if (!this.views.scmGroupedViews.has(type)) {
5454
type = first(this.views.scmGroupedViews) as T;
5555
}
@@ -61,7 +61,9 @@ export class ScmGroupedView implements Disposable {
6161

6262
this._view?.dispose();
6363
this._view = this.getView(type);
64-
void this._view.show({ preserveFocus: false });
64+
if (focus) {
65+
void this._view.show({ preserveFocus: false });
66+
}
6567
this.views.lastSelectedScmGroupedView = type;
6668

6769
return this._view as TreeViewByType[T];

src/views/stashesView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class StashesRepositoryNode extends RepositoryFolderNode<StashesView, Sta
3434

3535
export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView, StashesRepositoryNode> {
3636
async getChildren(): Promise<ViewNode[]> {
37-
this.view.description = this.getViewDescription();
37+
this.view.description = this.view.getViewDescription();
3838
this.view.message = undefined;
3939

4040
if (this.children == null) {
@@ -69,7 +69,7 @@ export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView,
6969
return [];
7070
}
7171

72-
this.view.description = this.getViewDescription(stash.commits.size);
72+
this.view.description = this.view.getViewDescription(stash.commits.size);
7373

7474
return child.getChildren();
7575
}

src/views/tagsView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class TagsRepositoryNode extends RepositoryFolderNode<TagsView, TagsNode>
3535

3636
export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRepositoryNode> {
3737
async getChildren(): Promise<ViewNode[]> {
38-
this.view.description = this.getViewDescription();
38+
this.view.description = this.view.getViewDescription();
3939
this.view.message = undefined;
4040

4141
if (this.children == null) {
@@ -70,7 +70,7 @@ export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRe
7070
return [];
7171
}
7272

73-
this.view.description = this.getViewDescription(tags.values.length);
73+
this.view.description = this.view.getViewDescription(tags.values.length);
7474

7575
return child.getChildren();
7676
}

src/views/viewBase.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ export abstract class ViewBase<
212212
private readonly trackingFeature: TrackedUsageFeatures,
213213
public readonly grouped?: boolean,
214214
) {
215-
if (this.grouped) {
216-
this.description = this.name.toLocaleLowerCase();
217-
}
215+
this.description = this.getViewDescription();
218216
this.disposables.push(once(container.onReady)(this.onReady, this));
219217

220218
if (this.container.debugging || configuration.get('debug')) {
@@ -440,6 +438,13 @@ export abstract class ViewBase<
440438
return node.getTreeItem();
441439
}
442440

441+
getViewDescription(count?: number) {
442+
return (
443+
`${this.grouped ? `${this.name.toLocaleLowerCase()} ` : ''}${count != null ? `(${count})` : ''}` ||
444+
undefined
445+
);
446+
}
447+
443448
resolveTreeItem(item: TreeItem, node: ViewNode, token: CancellationToken): TreeItem | Promise<TreeItem> {
444449
return node.resolveTreeItem?.(item, token) ?? item;
445450
}

src/views/views.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,20 @@ export class Views implements Disposable {
244244
private async toggleScmViewGrouping(type: GroupableTreeViewTypes, grouped: boolean) {
245245
if (grouped) {
246246
if (!this._scmGroupedViews.has(type)) {
247-
this.lastSelectedScmGroupedView = type;
248247
this._scmGroupedViews.add(type);
248+
this.lastSelectedScmGroupedView = type;
249249
}
250250
} else if (this._scmGroupedViews.has(type)) {
251+
this._scmGroupedViews.delete(type);
251252
if (type === this.lastSelectedScmGroupedView) {
252-
this.lastSelectedScmGroupedView = undefined;
253+
this.lastSelectedScmGroupedView = first(this._scmGroupedViews);
253254
}
254-
this._scmGroupedViews.delete(type);
255255
}
256256

257257
await updateScmGroupedViewsInConfig(this._scmGroupedViews);
258258

259259
// Show the view after the configuration change has been applied
260-
setTimeout(() => executeCoreCommand(`gitlens.views.${type}.focus`), 1);
260+
setTimeout(() => executeCoreCommand(`gitlens.views.${grouped ? 'scm.grouped' : type}.focus`), 1);
261261
}
262262

263263
private updateScmGroupedViewsRegistration() {

0 commit comments

Comments
 (0)