Skip to content

Commit 2ff68a2

Browse files
committed
Test sidebar size change
1 parent 2e65e66 commit 2ff68a2

File tree

4 files changed

+78
-50
lines changed

4 files changed

+78
-50
lines changed

CodeEdit/Features/Git/Client/GitClient+CommitHistory.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ extension GitClient {
4040
return output
4141
.split(separator: "\n")
4242
.map { line -> GitCommit in
43-
let parameters = line.components(separatedBy: "¦")
43+
let parameters = String(line).components(separatedBy: "¦")
4444
let infoRef = parameters[safe: 9]
45-
46-
var ref = ""
45+
var refs: [String] = []
4746
var tag = ""
48-
4947
if let infoRef = infoRef {
5048
if infoRef.contains("tag:") {
5149
tag = infoRef.components(separatedBy: "tag:")[1].trimmingCharacters(in: .whitespaces)
5250
} else {
53-
let refs = infoRef.split(separator: ",")
54-
ref = refs.count > 1 ? String(refs[1]).trimmingCharacters(in: .whitespaces) : ""
51+
refs = infoRef.split(separator: ",").compactMap {
52+
var element = String($0)
53+
if element.contains("origin/HEAD") { return nil }
54+
if element.contains("HEAD -> ") { element = element.replacingOccurrences(of: "HEAD -> ", with: "") }
55+
return element.trimmingCharacters(in: .whitespaces)
56+
}
5557
}
5658
}
5759

@@ -64,7 +66,7 @@ extension GitClient {
6466
committer: parameters[safe: 5] ?? "",
6567
committerEmail: parameters[safe: 6] ?? "",
6668
body: parameters[safe: 8] ?? "",
67-
ref: ref,
69+
refs: refs,
6870
tag: tag,
6971
remoteURL: remoteURL,
7072
date: dateFormatter.date(from: parameters[safe: 7] ?? "") ?? Date()

CodeEdit/Features/Git/Client/Models/GitCommit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct GitCommit: Equatable, Hashable, Identifiable {
1818
let committer: String
1919
let committerEmail: String
2020
let body: String
21-
let ref: String
21+
let refs: [String]
2222
let tag: String
2323
let remoteURL: URL?
2424
let date: Date

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitListItemView.swift

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftUI
1010
struct CommitListItemView: View {
1111

1212
var commit: GitCommit
13+
var width: CGFloat?
1314

1415
private var defaultAvatar: some View {
1516
Image(systemName: "person.crop.circle.fill")
@@ -48,6 +49,8 @@ struct CommitListItemView: View {
4849

4950
init(commit: GitCommit) {
5051
self.commit = commit
52+
//self.width = width
53+
//print("CGFloat", width)
5154
}
5255

5356
var body: some View {
@@ -68,42 +71,47 @@ struct CommitListItemView: View {
6871
}
6972
}
7073
VStack(alignment: .leading, spacing: 0) {
71-
Text(commit.author)
72-
.fontWeight(.bold)
73-
.font(.system(size: 11))
74-
75-
if !commit.ref.isEmpty {
76-
HStack {
77-
Image.branch
78-
.imageScale(.small)
79-
.foregroundColor(.primary)
80-
Text(commit.ref)
81-
.font(.system(size: 10, design: .monospaced))
74+
HStack {
75+
Text(commit.author)
76+
.fontWeight(.bold)
77+
.font(.system(size: 11))
78+
if !commit.refs.isEmpty {
79+
HStack {
80+
ForEach(commit.refs, id: \.self) { ref in
81+
HStack {
82+
Image.branch
83+
.imageScale(.small)
84+
.foregroundColor(.primary)
85+
Text(ref)
86+
.font(.system(size: 10, design: .monospaced))
87+
}
88+
.background(
89+
RoundedRectangle(cornerRadius: 3)
90+
.padding(.vertical, -1)
91+
.padding(.horizontal, -2.5)
92+
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
93+
)
94+
.padding(.trailing, 2.5)
95+
}
96+
}
8297
}
83-
.background(
84-
RoundedRectangle(cornerRadius: 3)
85-
.padding(.vertical, -1)
86-
.padding(.horizontal, -2.5)
87-
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
88-
)
89-
.padding(.trailing, 2.5)
90-
}
9198

92-
if !commit.tag.isEmpty {
93-
HStack {
94-
Image.breakpoint
95-
.imageScale(.small)
96-
.foregroundColor(.primary)
97-
Text(commit.tag)
98-
.font(.system(size: 10, design: .monospaced))
99+
if !commit.tag.isEmpty {
100+
HStack {
101+
Image.breakpoint
102+
.imageScale(.small)
103+
.foregroundColor(.primary)
104+
Text(commit.tag)
105+
.font(.system(size: 10, design: .monospaced))
106+
}
107+
.background(
108+
RoundedRectangle(cornerRadius: 3)
109+
.padding(.vertical, -1)
110+
.padding(.horizontal, -2.5)
111+
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
112+
)
113+
.padding(.trailing, 2.5)
99114
}
100-
.background(
101-
RoundedRectangle(cornerRadius: 3)
102-
.padding(.vertical, -1)
103-
.padding(.horizontal, -2.5)
104-
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
105-
)
106-
.padding(.trailing, 2.5)
107115
}
108116

109117
Text("\(commit.message) \(commit.body)")

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/SourceControlNavigatorHistoryView.swift

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct SourceControlNavigatorHistoryView: View {
2121
@State var commitHistory: [GitCommit] = []
2222

2323
@State var selection: GitCommit?
24+
@State var width: CGFloat?
2425

2526
func updateCommitHistory() async {
2627
do {
@@ -55,17 +56,23 @@ struct SourceControlNavigatorHistoryView: View {
5556
if commitHistory.isEmpty {
5657
CEContentUnavailableView("No History")
5758
} else {
58-
ZStack {
59-
List(selection: $selection) {
60-
ForEach(commitHistory) { commit in
61-
CommitListItemView(commit: commit)
62-
.tag(commit)
63-
.listRowSeparator(.hidden)
59+
GeometryReader { geometry in
60+
ZStack {
61+
List(selection: $selection) {
62+
ForEach(commitHistory) { commit in
63+
CommitListItemView(commit: commit)
64+
.tag(commit)
65+
.listRowSeparator(.hidden)
66+
}
67+
}
68+
.opacity(selection == nil ? 1 : 0)
69+
if selection != nil {
70+
CommitDetailsView(commit: $selection)
6471
}
6572
}
66-
.opacity(selection == nil ? 1 : 0)
67-
if selection != nil {
68-
CommitDetailsView(commit: $selection)
73+
.onChange(of: geometry.size.width) { newWidth in
74+
width = newWidth
75+
print(newWidth)
6976
}
7077
}
7178
}
@@ -94,3 +101,14 @@ struct SourceControlNavigatorHistoryView: View {
94101
}
95102
}
96103
}
104+
/*
105+
.gesture(
106+
DragGesture(minimumDistance: 0)
107+
.onChanged({ value in
108+
print(value)
109+
})
110+
.onEnded({ value in
111+
print(value)
112+
})
113+
)
114+
*/

0 commit comments

Comments
 (0)