Skip to content

Commit

Permalink
fix: git branches dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
FezVrasta committed Jan 22, 2024
1 parent a445dcf commit 8ae6966
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
85773E1E2A3E0A1F00C5D926 /* SettingsSearchResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85773E1D2A3E0A1F00C5D926 /* SettingsSearchResult.swift */; };
85CD0C5F2A10CC3200E531FD /* URL+isImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85CD0C5E2A10CC3200E531FD /* URL+isImage.swift */; };
85E4122A2A46C8CA00183F2B /* LocationsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85E412292A46C8CA00183F2B /* LocationsSettings.swift */; };
9D36E1BF2B5E7D7500443C41 /* GitBranchesGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */; };
B6041F4D29D7A4E9000F3454 /* SettingsPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6041F4C29D7A4E9000F3454 /* SettingsPageView.swift */; };
B6041F5229D7D6D6000F3454 /* SettingsWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6041F5129D7D6D6000F3454 /* SettingsWindow.swift */; };
B607181D2B0C5BE3009CDAB4 /* GitClient+Stash.swift in Sources */ = {isa = PBXBuildFile; fileRef = B607181C2B0C5BE3009CDAB4 /* GitClient+Stash.swift */; };
Expand Down Expand Up @@ -885,6 +886,7 @@
85773E1D2A3E0A1F00C5D926 /* SettingsSearchResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSearchResult.swift; sourceTree = "<group>"; };
85CD0C5E2A10CC3200E531FD /* URL+isImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+isImage.swift"; sourceTree = "<group>"; };
85E412292A46C8CA00183F2B /* LocationsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsSettings.swift; sourceTree = "<group>"; };
9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitBranchesGroup.swift; sourceTree = "<group>"; };
B6041F4C29D7A4E9000F3454 /* SettingsPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsPageView.swift; sourceTree = "<group>"; };
B6041F5129D7D6D6000F3454 /* SettingsWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWindow.swift; sourceTree = "<group>"; };
B607181C2B0C5BE3009CDAB4 /* GitClient+Stash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Stash.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1951,6 +1953,7 @@
04BA7C0A2AE2A2D100584E1C /* GitBranch.swift */,
B65B10F12B07D34F002852CF /* GitRemote.swift */,
B607181F2B0C6CE7009CDAB4 /* GitStashEntry.swift */,
9D36E1BE2B5E7D7500443C41 /* GitBranchesGroup.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -3251,6 +3254,7 @@
B6F0517D29D9E4B100D72287 /* TerminalSettingsView.swift in Sources */,
587B9E8C29301D8F00AC7927 /* GitHubOpenness.swift in Sources */,
5894E59729FEF7740077E59C /* CEWorkspaceFile+Recursion.swift in Sources */,
9D36E1BF2B5E7D7500443C41 /* GitBranchesGroup.swift in Sources */,
587B9E8229301D8F00AC7927 /* GitHubPreviewHeader.swift in Sources */,
611191FC2B08CCB800D4459B /* SearchIndexer+AsyncController.swift in Sources */,
58F2EB02292FB2B0004A9BDE /* Loopable.swift in Sources */,
Expand Down
27 changes: 25 additions & 2 deletions CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,34 @@ struct ToolbarBranchPicker: View {

let branches = sourceControlManager.branches
.filter({ $0.isLocal && $0 != sourceControlManager.currentBranch })
let branchesGroups = branches.reduce(into: [String: GitBranchesGroup]()) { result, branch in
guard let branchPrefix = branch.name.components(separatedBy: "/").first else {
return
}

result[
branchPrefix,
default: GitBranchesGroup(name: branchPrefix, branches: [])
].branches.append(branch)
}

if !branches.isEmpty {
VStack(alignment: .leading, spacing: 0) {
headerLabel("Branches")
ForEach(branches, id: \.self) { branch in
BranchCell(sourceControlManager: sourceControlManager, branch: branch)
ForEach(branchesGroups.keys.sorted(), id: \.self) { branchGroupPrefix in
if let group = branchesGroups[branchGroupPrefix] {
if !group.shouldNest {
BranchCell(sourceControlManager: sourceControlManager, branch: group.branches.first!)
} else {
Menu(content: {
ForEach(group.branches, id: \.self) { branch in
BranchCell(sourceControlManager: sourceControlManager, branch: branch)
}
}) {
Text(group.name)
}
}
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions CodeEdit/Features/Git/Client/Models/GitBranchesGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GitBranchesGroup.swift
// CodeEdit
//
// Created by Federico Zivolo on 22/01/24.
//

import Foundation

struct GitBranchesGroup: Hashable {
let name: String
var branches: [GitBranch]
var shouldNest: Bool {
branches.first?.name.hasPrefix(name + "/") ?? false
}
}

0 comments on commit 8ae6966

Please sign in to comment.