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)
}
}