Skip to content

Commit f6d82b6

Browse files
phlpsongtom-ludwig
andauthored
Git branches list order and truncate priority issue (#1647)
* fix: branches list order issue and truncate priority of name * Update SourceControlManager.swift Co-authored-by: Tom Ludwig <tommludwig@icloud.com> * fix: optimize branch picker list issue and use lowercase to sort --------- Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
1 parent e13e7da commit f6d82b6

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ struct ToolbarBranchPicker: View {
112112
}
113113
}
114114

115-
let branches = sourceControlManager.branches
116-
.filter({ $0.isLocal && $0 != sourceControlManager.currentBranch })
115+
let branches = sourceControlManager.orderedLocalBranches
116+
.filter({ $0 != sourceControlManager.currentBranch })
117117
let branchesGroups = branches.reduce(into: [String: GitBranchesGroup]()) { result, branch in
118118
guard let branchPrefix = branch.name.components(separatedBy: "/").first else {
119119
return
120120
}
121121

122122
result[
123-
branchPrefix,
123+
branchPrefix.lowercased(),
124124
default: GitBranchesGroup(name: branchPrefix, branches: [])
125125
].branches.append(branch)
126126
}

CodeEdit/Features/Git/SourceControlManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ final class SourceControlManager: ObservableObject {
3838

3939
@Published var isGitRepository: Bool = false
4040

41+
var orderedLocalBranches: [GitBranch] {
42+
var orderedBranches: [GitBranch] = [currentBranch].compactMap { $0 }
43+
let otherBranches = branches.filter { $0.isLocal && $0 != currentBranch }
44+
.sorted { $0.name.lowercased() < $1.name.lowercased() }
45+
orderedBranches.append(contentsOf: otherBranches)
46+
return orderedBranches
47+
}
48+
4149
init(
4250
workspaceURL: URL,
4351
editorManager: EditorManager

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Repository/Views/SourceControlNavigatorRepositoryItem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct SourceControlNavigatorRepositoryItem: View {
2424
.lineLimit(1)
2525
.foregroundStyle(.secondary)
2626
.font(.system(size: 11))
27+
.layoutPriority(-1)
2728
}
2829
Spacer()
2930
HStack(spacing: 5) {

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Repository/Views/SourceControlNavigatorRepositoryView+outlineGroupData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension SourceControlNavigatorRepositoryView {
1515
label: "Branches",
1616
systemImage: "externaldrive.fill",
1717
imageColor: Color(nsColor: .secondaryLabelColor),
18-
children: sourceControlManager.branches.filter({ $0.isLocal }).map { branch in
18+
children: sourceControlManager.orderedLocalBranches.map { branch in
1919
.init(
2020
id: "Branch\(branch.name)",
2121
label: branch.name,

0 commit comments

Comments
 (0)