Skip to content

Commit 8ae6966

Browse files
committed
fix: git branches dropdown
1 parent a445dcf commit 8ae6966

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370
85773E1E2A3E0A1F00C5D926 /* SettingsSearchResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85773E1D2A3E0A1F00C5D926 /* SettingsSearchResult.swift */; };
371371
85CD0C5F2A10CC3200E531FD /* URL+isImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85CD0C5E2A10CC3200E531FD /* URL+isImage.swift */; };
372372
85E4122A2A46C8CA00183F2B /* LocationsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85E412292A46C8CA00183F2B /* LocationsSettings.swift */; };
373+
9D36E1BF2B5E7D7500443C41 /* GitBranchesGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */; };
373374
B6041F4D29D7A4E9000F3454 /* SettingsPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6041F4C29D7A4E9000F3454 /* SettingsPageView.swift */; };
374375
B6041F5229D7D6D6000F3454 /* SettingsWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6041F5129D7D6D6000F3454 /* SettingsWindow.swift */; };
375376
B607181D2B0C5BE3009CDAB4 /* GitClient+Stash.swift in Sources */ = {isa = PBXBuildFile; fileRef = B607181C2B0C5BE3009CDAB4 /* GitClient+Stash.swift */; };
@@ -885,6 +886,7 @@
885886
85773E1D2A3E0A1F00C5D926 /* SettingsSearchResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSearchResult.swift; sourceTree = "<group>"; };
886887
85CD0C5E2A10CC3200E531FD /* URL+isImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+isImage.swift"; sourceTree = "<group>"; };
887888
85E412292A46C8CA00183F2B /* LocationsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsSettings.swift; sourceTree = "<group>"; };
889+
9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitBranchesGroup.swift; sourceTree = "<group>"; };
888890
B6041F4C29D7A4E9000F3454 /* SettingsPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsPageView.swift; sourceTree = "<group>"; };
889891
B6041F5129D7D6D6000F3454 /* SettingsWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWindow.swift; sourceTree = "<group>"; };
890892
B607181C2B0C5BE3009CDAB4 /* GitClient+Stash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Stash.swift"; sourceTree = "<group>"; };
@@ -1951,6 +1953,7 @@
19511953
04BA7C0A2AE2A2D100584E1C /* GitBranch.swift */,
19521954
B65B10F12B07D34F002852CF /* GitRemote.swift */,
19531955
B607181F2B0C6CE7009CDAB4 /* GitStashEntry.swift */,
1956+
9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */,
19541957
);
19551958
path = Models;
19561959
sourceTree = "<group>";
@@ -3251,6 +3254,7 @@
32513254
B6F0517D29D9E4B100D72287 /* TerminalSettingsView.swift in Sources */,
32523255
587B9E8C29301D8F00AC7927 /* GitHubOpenness.swift in Sources */,
32533256
5894E59729FEF7740077E59C /* CEWorkspaceFile+Recursion.swift in Sources */,
3257+
9D36E1BF2B5E7D7500443C41 /* GitBranchesGroup.swift in Sources */,
32543258
587B9E8229301D8F00AC7927 /* GitHubPreviewHeader.swift in Sources */,
32553259
611191FC2B08CCB800D4459B /* SearchIndexer+AsyncController.swift in Sources */,
32563260
58F2EB02292FB2B0004A9BDE /* Loopable.swift in Sources */,

CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,34 @@ struct ToolbarBranchPicker: View {
115115

116116
let branches = sourceControlManager.branches
117117
.filter({ $0.isLocal && $0 != sourceControlManager.currentBranch })
118+
let branchesGroups = branches.reduce(into: [String: GitBranchesGroup]()) { result, branch in
119+
guard let branchPrefix = branch.name.components(separatedBy: "/").first else {
120+
return
121+
}
122+
123+
result[
124+
branchPrefix,
125+
default: GitBranchesGroup(name: branchPrefix, branches: [])
126+
].branches.append(branch)
127+
}
128+
118129
if !branches.isEmpty {
119130
VStack(alignment: .leading, spacing: 0) {
120131
headerLabel("Branches")
121-
ForEach(branches, id: \.self) { branch in
122-
BranchCell(sourceControlManager: sourceControlManager, branch: branch)
132+
ForEach(branchesGroups.keys.sorted(), id: \.self) { branchGroupPrefix in
133+
if let group = branchesGroups[branchGroupPrefix] {
134+
if !group.shouldNest {
135+
BranchCell(sourceControlManager: sourceControlManager, branch: group.branches.first!)
136+
} else {
137+
Menu(content: {
138+
ForEach(group.branches, id: \.self) { branch in
139+
BranchCell(sourceControlManager: sourceControlManager, branch: branch)
140+
}
141+
}) {
142+
Text(group.name)
143+
}
144+
}
145+
}
123146
}
124147
}
125148
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// GitBranchesGroup.swift
3+
// CodeEdit
4+
//
5+
// Created by Federico Zivolo on 22/01/24.
6+
//
7+
8+
import Foundation
9+
10+
struct GitBranchesGroup: Hashable {
11+
let name: String
12+
var branches: [GitBranch]
13+
var shouldNest: Bool {
14+
branches.first?.name.hasPrefix(name + "/") ?? false
15+
}
16+
}

0 commit comments

Comments
 (0)