Skip to content

Commit e63888c

Browse files
committed
Adds compact setting to views with branches/tags
- Avoids reusing the compact file setting Avoids single-child compacting unless compact mode is enabled
1 parent 7b99079 commit e63888c

File tree

8 files changed

+79
-21
lines changed

8 files changed

+79
-21
lines changed

package.json

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,13 +2263,20 @@
22632263
"tree"
22642264
],
22652265
"enumDescriptions": [
2266-
"Displays branches as a list",
2267-
"Displays branches as a tree when branch names contain slashes `/`"
2266+
"Displays branches and tags as a list",
2267+
"Displays branches and tags as a tree when names contain slashes `/`"
22682268
],
2269-
"markdownDescription": "Specifies how the _Repositories_ view will display branches",
2269+
"markdownDescription": "Specifies how the _Repositories_ view will display branches and tags",
22702270
"scope": "window",
22712271
"order": 70
22722272
},
2273+
"gitlens.views.repositories.branches.compact": {
2274+
"type": "boolean",
2275+
"default": true,
2276+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary branch and tag nesting in the _Repositories_ view. Only applies when `#gitlens.views.repositories.branches.layout#` is set to `tree`",
2277+
"scope": "window",
2278+
"order": 71
2279+
},
22732280
"gitlens.views.repositories.files.layout": {
22742281
"type": "string",
22752282
"default": "auto",
@@ -2572,12 +2579,19 @@
25722579
],
25732580
"enumDescriptions": [
25742581
"Displays branches as a list",
2575-
"Displays branches as a tree when branch names contain slashes `/`"
2582+
"Displays branches as a tree when names contain slashes `/`"
25762583
],
25772584
"markdownDescription": "Specifies how the _Branches_ view will display branches",
25782585
"scope": "window",
25792586
"order": 30
25802587
},
2588+
"gitlens.views.branches.branches.compact": {
2589+
"type": "boolean",
2590+
"default": true,
2591+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary branch nesting in the _Branches_ view. Only applies when `#gitlens.views.branches.branches.layout#` is set to `tree`",
2592+
"scope": "window",
2593+
"order": 31
2594+
},
25812595
"gitlens.views.branches.files.layout": {
25822596
"type": "string",
25832597
"default": "auto",
@@ -2675,12 +2689,19 @@
26752689
],
26762690
"enumDescriptions": [
26772691
"Displays branches as a list",
2678-
"Displays branches as a tree when branch names contain slashes `/`"
2692+
"Displays branches as a tree when names contain slashes `/`"
26792693
],
26802694
"markdownDescription": "Specifies how the _Remotes_ view will display branches",
26812695
"scope": "window",
26822696
"order": 20
26832697
},
2698+
"gitlens.views.remotes.branches.compact": {
2699+
"type": "boolean",
2700+
"default": true,
2701+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary branch nesting in the _Remotes_ view. Only applies when `#gitlens.views.remotes.branches.layout#` is set to `tree`",
2702+
"scope": "window",
2703+
"order": 21
2704+
},
26842705
"gitlens.views.remotes.files.layout": {
26852706
"type": "string",
26862707
"default": "auto",
@@ -2817,12 +2838,19 @@
28172838
],
28182839
"enumDescriptions": [
28192840
"Displays tags as a list",
2820-
"Displays tags as a tree when tags names contain slashes `/`"
2841+
"Displays tags as a tree when names contain slashes `/`"
28212842
],
28222843
"markdownDescription": "Specifies how the _Tags_ view will display tags",
28232844
"scope": "window",
28242845
"order": 10
28252846
},
2847+
"gitlens.views.tags.branches.compact": {
2848+
"type": "boolean",
2849+
"default": true,
2850+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary tag nesting in the _Tags_ view. Only applies when `#gitlens.views.tags.branches.layout#` is set to `tree`",
2851+
"scope": "window",
2852+
"order": 11
2853+
},
28262854
"gitlens.views.tags.files.layout": {
28272855
"type": "string",
28282856
"default": "auto",
@@ -2997,12 +3025,19 @@
29973025
],
29983026
"enumDescriptions": [
29993027
"Displays worktree branches as a list",
3000-
"Displays worktree branches as a tree when branch names contain slashes `/`"
3028+
"Displays worktree branches as a tree when names contain slashes `/`"
30013029
],
30023030
"markdownDescription": "Specifies how the _Worktrees_ view will display worktree branches",
30033031
"scope": "window",
30043032
"order": 35
30053033
},
3034+
"gitlens.views.worktrees.branches.compact": {
3035+
"type": "boolean",
3036+
"default": true,
3037+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary branch nesting in the _Worktrees_ view. Only applies when `#gitlens.views.worktrees.branches.layout#` is set to `tree`",
3038+
"scope": "window",
3039+
"order": 36
3040+
},
30063041
"gitlens.views.worktrees.files.layout": {
30073042
"type": "string",
30083043
"default": "auto",
@@ -3492,13 +3527,20 @@
34923527
"tree"
34933528
],
34943529
"enumDescriptions": [
3495-
"Displays branches as a list",
3496-
"Displays branches as a tree when branch names contain slashes `/`"
3530+
"Displays branches and tags as a list",
3531+
"Displays branches and tags as a tree when names contain slashes `/`"
34973532
],
3498-
"markdownDescription": "Specifies how the _Cloud Workspaces_ view will display branches",
3533+
"markdownDescription": "Specifies how the _Cloud Workspaces_ view will display branches and tags",
34993534
"scope": "window",
35003535
"order": 70
35013536
},
3537+
"gitlens.views.workspaces.branches.compact": {
3538+
"type": "boolean",
3539+
"default": true,
3540+
"markdownDescription": "Specifies whether to compact (flatten) unnecessary branch and tag nesting in the _Cloud Workspaces_ view. Only applies when `#gitlens.views.workspaces.branches.layout#` is set to `tree`",
3541+
"scope": "window",
3542+
"order": 71
3543+
},
35023544
"gitlens.views.workspaces.worktrees.viewAs": {
35033545
"type": "string",
35043546
"default": "name",

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ export type ViewsConfig = ViewsCommonConfig & ViewsConfigs;
806806
export interface BranchesViewConfig {
807807
readonly avatars: boolean;
808808
readonly branches: {
809+
readonly compact: boolean;
809810
readonly layout: ViewBranchesLayout;
810811
};
811812
readonly files: ViewsFilesConfig;
@@ -908,6 +909,7 @@ export interface PullRequestViewConfig {
908909
export interface RemotesViewConfig {
909910
readonly avatars: boolean;
910911
readonly branches: {
912+
readonly compact: boolean;
911913
readonly layout: ViewBranchesLayout;
912914
};
913915
readonly files: ViewsFilesConfig;
@@ -924,6 +926,7 @@ export interface RepositoriesViewConfig {
924926
readonly autoReveal: boolean;
925927
readonly avatars: boolean;
926928
readonly branches: {
929+
readonly compact: boolean;
927930
readonly layout: ViewBranchesLayout;
928931
readonly showBranchComparison: false | Extract<ViewShowBranchComparison, 'branch'>;
929932
readonly showStashes: boolean;
@@ -968,6 +971,7 @@ export interface StashesViewConfig {
968971
export interface TagsViewConfig {
969972
readonly avatars: boolean;
970973
readonly branches: {
974+
readonly compact: boolean;
971975
readonly layout: ViewBranchesLayout;
972976
};
973977
readonly files: ViewsFilesConfig;
@@ -979,6 +983,7 @@ export type ViewWorktreesViewAs = 'name' | 'path' | 'relativePath';
979983
export interface WorktreesViewConfig {
980984
readonly avatars: boolean;
981985
readonly branches: {
986+
readonly compact: boolean;
982987
readonly layout: ViewBranchesLayout;
983988
};
984989
readonly files: ViewsFilesConfig;
@@ -998,6 +1003,7 @@ export interface WorktreesViewConfig {
9981003
export interface WorkspacesViewConfig {
9991004
readonly avatars: boolean;
10001005
readonly branches: {
1006+
readonly compact: boolean;
10011007
readonly layout: ViewBranchesLayout;
10021008
readonly showBranchComparison: false | Extract<ViewShowBranchComparison, 'branch'>;
10031009
readonly showStashes: boolean;

src/views/nodes/branchOrTagFolderNode.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
22
import { GitUri } from '../../git/gitUri';
33
import type { HierarchicalItem } from '../../system/array';
44
import { first } from '../../system/iterable';
5-
import type { View } from '../viewBase';
5+
import type {
6+
ViewsWithBranchesNode,
7+
ViewsWithRemotesNode,
8+
ViewsWithTagsNode,
9+
ViewsWithWorktreesNode,
10+
} from '../viewBase';
611
import { ContextValues, getViewNodeId, ViewNode } from './abstract/viewNode';
712
import type { BranchNode } from './branchNode';
813
import type { TagNode } from './tagNode';
914
import type { WorktreeNode } from './worktreeNode';
1015

11-
export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
16+
export class BranchOrTagFolderNode extends ViewNode<
17+
'branch-tag-folder',
18+
ViewsWithBranchesNode | ViewsWithRemotesNode | ViewsWithTagsNode | ViewsWithWorktreesNode
19+
> {
1220
constructor(
13-
view: View,
21+
view: ViewsWithBranchesNode | ViewsWithRemotesNode | ViewsWithTagsNode | ViewsWithWorktreesNode,
1422
protected override readonly parent: ViewNode,
1523
public readonly folderType: 'branch' | 'remote-branch' | 'tag' | 'worktree',
1624
public readonly root: HierarchicalItem<BranchNode | TagNode | WorktreeNode>,
@@ -33,9 +41,10 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
3341
}
3442

3543
getChildren(): ViewNode[] {
36-
if (this.root.descendants == null || this.root.children == null) return [];
44+
if (!this.root.descendants?.length || !this.root.children?.size) return [];
3745

3846
const children: (BranchOrTagFolderNode | BranchNode | TagNode | WorktreeNode)[] = [];
47+
const { compact } = this.view.config.branches;
3948

4049
for (const folder of this.root.children.values()) {
4150
if (folder.value != null) {
@@ -45,7 +54,7 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
4554
}
4655

4756
if (!folder.children?.size) continue;
48-
if (folder.children.size === 1) {
57+
if (folder.children.size === 1 && compact) {
4958
const child = first(folder.children.values());
5059
if (child?.value != null) {
5160
// Make sure to set the parent

src/views/nodes/branchesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
9999
branchNodes,
100100
n => n.treeHierarchy,
101101
(...paths) => paths.join('/'),
102-
this.view.config.files.compact,
102+
this.view.config.branches.compact,
103103
b => {
104104
b.compacted = true;
105105
return true;

src/views/nodes/folderNode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export class FolderNode extends ViewNode<'folder', ViewsWithCommits | StashesVie
4545
}
4646

4747
getChildren(): (FolderNode | FileNode)[] {
48-
if (this.root.descendants == null || this.root.children == null) return [];
48+
if (!this.root.descendants?.length || !this.root.children?.size) return [];
4949

5050
let children: (FolderNode | FileNode)[];
51+
const { compact } = this.view.config.files;
5152

5253
const nesting = FolderNode.getFileNesting(
5354
this.view.config.files,
@@ -68,7 +69,7 @@ export class FolderNode extends ViewNode<'folder', ViewsWithCommits | StashesVie
6869
}
6970

7071
if (!folder.children?.size) continue;
71-
if (folder.children.size === 1) {
72+
if (folder.children.size === 1 && compact) {
7273
const child = first(folder.children.values());
7374
if (child?.value != null) {
7475
// Make sure to set the parent

src/views/nodes/remoteNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class RemoteNode extends ViewNode<'remote', ViewsWithRemotes> {
6262
branchNodes,
6363
n => n.treeHierarchy,
6464
(...paths) => paths.join('/'),
65-
this.view.config.files.compact,
65+
this.view.config.branches.compact,
6666
b => {
6767
b.compacted = true;
6868
return true;

src/views/nodes/tagsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class TagsNode extends CacheableChildrenViewNode<'tags', ViewsWithTagsNod
4646
tagNodes,
4747
n => n.tag.name.split('/'),
4848
(...paths) => paths.join('/'),
49-
this.view.config.files.compact,
49+
this.view.config.branches.compact,
5050
);
5151

5252
const root = new BranchOrTagFolderNode(this.view, this, 'tag', hierarchy, this.repo.path, '', undefined);

src/views/nodes/worktreesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class WorktreesNode extends CacheableChildrenViewNode<'worktrees', ViewsW
6969
worktreeNodes,
7070
n => n.treeHierarchy,
7171
(...paths) => paths.join('/'),
72-
this.view.config.files.compact,
72+
this.view.config.branches.compact,
7373
w => {
7474
w.compacted = true;
7575
return true;

0 commit comments

Comments
 (0)