Improves Git's user interface

This commit is contained in:
2026-11-24 16:43:20 +01:00
parent 2887965a9e
commit 28079e80c5
6 changed files with 114 additions and 26 deletions
+16 -7
View File
@@ -2,7 +2,7 @@ import AppKit
import HelderCore
import SwiftUI
/// The message field over Gen. Commit Message, the author, the ⌘↵ hint and the three commit buttons.
/// The message field over the author, the ⌘↵ hint, Gen. Commit Message and the three commit buttons.
struct GitCommitBlock: View {
let model: WorkspaceModel
let store: SourceControlStore
@@ -22,13 +22,17 @@ struct GitCommitBlock: View {
}
.animation(Metrics.colorTransition, value: isFocused)
HStack(spacing: 16) {
GenerateMessageButton(model: model, store: store)
if let author = store.author {
Text(author).typeRole(Typography.path).foregroundStyle(Palette.textMuted).lineLimit(1)
.frame(minWidth: 0)
}
Text("⌘↵ commits").typeRole(Typography.path).foregroundStyle(Palette.text4).fixedSize()
Spacer(minLength: 0)
CommitButtons(model: model, store: store)
HStack(spacing: 8) {
GenerateMessageButton(model: model, store: store)
CommitButtons(model: model, store: store)
}
.layoutPriority(1)
}
.padding(.leading, 16)
.padding(.trailing, 14)
@@ -134,7 +138,7 @@ private struct CommitButtons: View {
}
}
/// Plex Mono 14/1.6 message field that grows with its wrapped text from 56 to 180pt, measured in `sizeThatFits`.
/// Right-aligned Plex Mono 14/1.6 message field that grows with its wrapped text from 56 to 180pt, measured in `sizeThatFits`.
struct GitMessageField: NSViewRepresentable {
let text: String
/// A new value takes first responder once, a run loop later: opening the view clears first responder first.
@@ -172,7 +176,9 @@ struct GitMessageField: NSViewRepresentable {
textView.textContainer?.widthTracksTextView = true
textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
textView.fillsClipView = true
textView.alignment = .right
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .right
paragraph.minimumLineHeight = role.lineHeight ?? 22.4
paragraph.maximumLineHeight = role.lineHeight ?? 22.4
textView.defaultParagraphStyle = paragraph
@@ -193,6 +199,7 @@ struct GitMessageField: NSViewRepresentable {
static func height(of text: String, width: CGFloat) -> CGFloat {
let role = Typography.commitMessage
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .right
paragraph.minimumLineHeight = role.lineHeight ?? 22.4
paragraph.maximumLineHeight = role.lineHeight ?? 22.4
let storage = NSTextStorage(string: text, attributes: [.font: role.nsFont, .paragraphStyle: paragraph])
@@ -252,7 +259,7 @@ struct GitMessageField: NSViewRepresentable {
}
/// Draws the placeholder and reports focus.
/// Draws the placeholder at the right inset and reports focus.
final class MessageTextView: PointerBoundTextView {
var placeholder = ""
var onFocusChange: ((Bool) -> Void)?
@@ -276,7 +283,9 @@ final class MessageTextView: PointerBoundTextView {
.font: font ?? Typography.commitMessage.nsFont, .foregroundColor: NSColor(hex: 0x6C7783),
.paragraphStyle: defaultParagraphStyle ?? NSParagraphStyle.default,
]
let origin = NSPoint(x: textContainerInset.width + (textContainer?.lineFragmentPadding ?? 0), y: textContainerInset.height)
(placeholder as NSString).draw(at: origin, withAttributes: attributes)
let text = placeholder as NSString
let inset = textContainerInset.width + (textContainer?.lineFragmentPadding ?? 0)
let origin = NSPoint(x: bounds.width - inset - text.size(withAttributes: attributes).width, y: textContainerInset.height)
text.draw(at: origin, withAttributes: attributes)
}
}
@@ -1,7 +1,7 @@
import HelderCore
import SwiftUI
/// The bottom strip's right end on a wide window: the last commits of the current branch, read-only.
/// The last commits of the current branch, read-only: under the branches in the side columns, else the strip's right end.
struct GitCommitsPanel: View {
let store: SourceControlStore
+68 -4
View File
@@ -10,10 +10,17 @@ struct GitView: View {
if let store = model.sourceControl {
VStack(spacing: 0) {
GitTopBar(model: model, store: store)
GitCommitBlock(model: model, store: store)
GitSectionsList(model: model, store: store)
.frame(maxHeight: .infinity)
GitBottomStrip(model: model, store: store)
GeometryReader { proxy in
switch GitBodyMode(width: proxy.size.width) {
case .sideColumns:
GitSideColumns(model: model, store: store, height: proxy.size.height)
case .bottomStrip:
VStack(spacing: 0) {
GitChanges(model: model, store: store)
GitBottomStrip(model: model, store: store)
}
}
}
}
} else {
Color.clear
@@ -25,6 +32,50 @@ struct GitView: View {
}
}
/// The commit block over the sections, filling the height it gets.
private struct GitChanges: View {
let model: WorkspaceModel
let store: SourceControlStore
var body: some View {
VStack(spacing: 0) {
GitCommitBlock(model: model, store: store)
GitSectionsList(model: model, store: store)
.frame(maxHeight: .infinity)
}
}
}
/// Branches over commits on the left, the changes in the middle, the console on the right, all full height.
private struct GitSideColumns: View {
let model: WorkspaceModel
let store: SourceControlStore
let height: CGFloat
var body: some View {
let half = max(0, (height - Metrics.hairline) / 2).rounded(.down)
HStack(spacing: 0) {
VStack(spacing: 0) {
GitBranchesPanel(model: model, store: store)
.frame(height: half)
Hairline()
GitCommitsPanel(store: store)
.frame(maxHeight: .infinity)
}
.frame(width: GitMetrics.sideColumnWidth)
.background(Palette.panel)
.hairline(.trailing)
GitChanges(model: model, store: store)
.frame(maxWidth: .infinity)
GitConsolePanel(model: model, store: store)
.frame(width: GitMetrics.consoleColumnWidth)
.frame(maxHeight: .infinity)
.background(Palette.panel)
.hairline(.leading)
}
}
}
/// The console left, the branches right, 230pt tall; a wide window adds the commit list after them.
private struct GitBottomStrip: View {
let model: WorkspaceModel
@@ -53,6 +104,16 @@ private struct GitBottomStrip: View {
}
}
/// How the body under the top bar is laid out for one window width.
enum GitBodyMode: Equatable {
case sideColumns
case bottomStrip
init(width: CGFloat) {
self = width >= GitMetrics.sideColumnsMinWidth ? .sideColumns : .bottomStrip
}
}
/// The widths of the bottom strip's panels for one strip width.
struct GitStripLayout: Equatable {
var console: CGFloat
@@ -97,6 +158,9 @@ enum GitMetrics {
static let consoleMaxWidth: CGFloat = 820
static let branchesMaxWidth: CGFloat = 820
static let commitsMinWidth: CGFloat = 260
static let sideColumnsMinWidth: CGFloat = 1600
static let sideColumnWidth: CGFloat = 480
static let consoleColumnWidth: CGFloat = 560
static let stripHeader: CGFloat = 32
static let branchRow: CGFloat = 28
}