Improves helder

This commit is contained in:
2026-10-05 09:24:25 +02:00
parent 8fafea4fc3
commit 336987d821
44 changed files with 3454 additions and 542 deletions
@@ -0,0 +1,128 @@
import SwiftUI
/// One button in a `ButtonGroup`. A toggle carries a state dot; an action has none.
public struct GroupItem {
public enum Kind: Equatable {
case action
case toggle(isOn: Bool)
}
var label: String
var keys: String?
var kind: Kind
var tip: Text
var action: () -> Void
public init(_ label: String, keys: String? = nil, kind: Kind, tip: Text, action: @escaping () -> Void) {
self.label = label
self.keys = keys
self.kind = kind
self.tip = tip
self.action = action
}
}
/// The title bar's shared button treatment: buttons edge to edge in one hairline box, a hairline between each.
public struct ButtonGroup: View {
var items: [GroupItem]
var tipEdge: HorizontalAlignment
public init(_ items: [GroupItem], tipEdge: HorizontalAlignment = .leading) {
self.items = items
self.tipEdge = tipEdge
}
public var body: some View {
HStack(spacing: 0) {
ForEach(Array(items.enumerated()), id: \.element.label) { index, item in
GroupButton(item: item, isFirst: index == 0, isLast: index == items.count - 1)
.tip(item.tip, edge: tipEdge)
}
}
.fixedSize()
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
}
}
/// The fill follows the group's rounded ends; the group is not clipped, so the tooltips can hang below it.
private struct GroupButton: View {
var item: GroupItem
var isFirst: Bool
var isLast: Bool
@State private var isHovered = false
var body: some View {
Button(action: item.action) {
HStack(spacing: Metrics.groupButtonGap) {
if case .toggle = item.kind {
Circle().fill(dotColor).frame(width: Metrics.groupButtonDot, height: Metrics.groupButtonDot)
}
Text(item.label).typeRole(Typography.button).foregroundStyle(labelColor)
if let keys = item.keys {
Text(keys).typeRole(Typography.keycapSmall).foregroundStyle(isOff ? Palette.text4 : Palette.amber)
}
}
.lineLimit(1)
.fixedSize()
.padding(Metrics.groupButtonPadding)
.background(fill, in: UnevenRoundedRectangle(cornerRadii: corners))
.overlay(alignment: .leading) {
if !isFirst { Rectangle().fill(Palette.raised).frame(width: Metrics.hairline) }
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onHover { isHovered = $0 }
.accessibilityAddTraits(isOn ? .isSelected : [])
.animation(Metrics.smallControlTransition, value: isHovered)
.animation(Metrics.smallControlTransition, value: item.kind)
}
private var isOn: Bool { item.kind == .toggle(isOn: true) }
private var isOff: Bool { item.kind == .toggle(isOn: false) }
private var labelColor: Color {
isOn ? Palette.text1 : isOff ? Palette.text4 : Palette.text3
}
private var dotColor: Color {
isOn ? Palette.amber : Palette.text5
}
private var fill: Color {
isOn ? Palette.amberTint : isHovered ? Palette.hover : .clear
}
private var corners: RectangleCornerRadii {
let r = Metrics.radiusSmall
return RectangleCornerRadii(topLeading: isFirst ? r : 0, bottomLeading: isFirst ? r : 0,
bottomTrailing: isLast ? r : 0, topTrailing: isLast ? r : 0)
}
}
/// The icon-only title-bar control (the `?`): a 26pt square with a hairline border.
public struct ToolbarIconButton: View {
var glyph: String
var action: () -> Void
@State private var isHovered = false
public init(_ glyph: String, action: @escaping () -> Void) {
self.glyph = glyph
self.action = action
}
public var body: some View {
Button(action: action) {
Text(glyph)
.typeRole(Typography.keycap)
.foregroundStyle(isHovered ? Palette.text1 : Palette.text4)
.frame(width: Metrics.toolbarIconButton, height: Metrics.toolbarIconButton)
.background(isHovered ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onHover { isHovered = $0 }
.animation(Metrics.smallControlTransition, value: isHovered)
}
}
+2 -12
View File
@@ -5,10 +5,6 @@ public struct Keycap: View {
public enum Style {
/// Amber glyph, raised border.
case normal
/// On an active toolbar toggle: the border turns amber.
case active
/// On a toggle that is off by meaning: glyph and border step back to text-4.
case muted
/// On an amber fill (primary button): ink glyph, ink border.
case onAmber
/// On an amber-deep fill (destructive button): light glyph, light border.
@@ -25,10 +21,6 @@ public struct Keycap: View {
role = small ? Typography.keycapSmall : Typography.keycap
}
public init(_ keys: String, highlighted: Bool) {
self.init(keys, style: highlighted ? .active : .normal)
}
public var body: some View {
Text(keys)
.typeRole(role)
@@ -41,8 +33,7 @@ public struct Keycap: View {
private var glyph: Color {
switch style {
case .normal, .active: Palette.amber
case .muted: Palette.text4
case .normal: Palette.amber
case .onAmber: Palette.ink
case .onDeep: Palette.onDeep
}
@@ -50,8 +41,7 @@ public struct Keycap: View {
private var border: Color {
switch style {
case .normal, .muted: Palette.raised
case .active: Palette.amberKeycapBorder
case .normal: Palette.raised
case .onAmber: Palette.inkKeycapBorder
case .onDeep: Palette.onDeep.opacity(0.4)
}
@@ -1,11 +1,11 @@
import SwiftUI
/// The frame every overlay sits in: a flat ink scrim (no blur) and a `panel` card with a hairline border,
/// radius 8 and the overlay shadow. `.inset` fills the window minus 34pt; `.sized` centres a fixed-width card
/// radius 8 and the overlay shadow. `.inset` fills the window minus 34pt, up to 1200pt wide; `.sized` centres a fixed-width card
/// at the top. A click on the scrim calls `onDismiss`.
public struct OverlayShell<Content: View>: View {
public enum Placement {
/// Search, Diff: the whole window minus the 34pt inset.
/// Search, Diff: the whole window minus the 34pt inset, at most `insetOverlayMaxWidth` wide.
case inset
/// A card of this width, top-aligned inside the inset.
case sized(width: CGFloat)
@@ -36,7 +36,7 @@ public struct OverlayShell<Content: View>: View {
switch placement {
case .inset:
OverlayCard { content }
.frame(maxWidth: .infinity, maxHeight: .infinity)
.frame(maxWidth: Metrics.insetOverlayMaxWidth, maxHeight: .infinity)
case let .sized(width):
OverlayCard { content }
.frame(width: width)
@@ -0,0 +1,50 @@
import AppKit
/// An NSTextView that only sets its I-beam while it is the view under the pointer.
/// On macOS 26 SwiftTerm makes the window send every mouse move to the first responder, and NSTextView
/// sets the I-beam on each one, which fights the arrow over the other columns and a splitter's resize cursor.
class PointerBoundTextView: NSTextView {
/// Grows the view to at least the clip view's height, so the empty area below the text still takes the I-beam and clicks.
var fillsClipView = false {
didSet { fitClipView() }
}
override func mouseMoved(with event: NSEvent) {
guard isUnderPointer else { return }
super.mouseMoved(with: event)
}
override func cursorUpdate(with event: NSEvent) {
guard isUnderPointer else { return }
super.cursorUpdate(with: event)
}
override func viewDidMoveToSuperview() {
super.viewDidMoveToSuperview()
NotificationCenter.default.removeObserver(self, name: NSView.frameDidChangeNotification, object: nil)
guard let clip = superview as? NSClipView else { return }
clip.postsFrameChangedNotifications = true
NotificationCenter.default.addObserver(self, selector: #selector(clipFrameChanged), name: NSView.frameDidChangeNotification,
object: clip)
fitClipView()
}
@objc private func clipFrameChanged() {
fitClipView()
}
private func fitClipView() {
guard fillsClipView, let clip = superview as? NSClipView else { return }
minSize.height = clip.bounds.height
sizeToFit()
}
/// A splitter's hit area lies on top of the text view's edge, so the visible rect alone is not enough.
private var isUnderPointer: Bool {
guard let window, let content = window.contentView else { return false }
let location = window.mouseLocationOutsideOfEventStream
guard visibleRect.contains(convert(location, from: nil)),
let hit = content.hitTest(content.superview?.convert(location, from: nil) ?? location) else { return false }
return hit.isDescendant(of: self)
}
}
+103 -31
View File
@@ -9,7 +9,6 @@ public struct Splitter: View {
var onEnd: () -> Void
@State private var isHovered = false
@State private var isDragging = false
@State private var last: CGFloat = 0
/// `.vertical` is a column divider dragged left and right; `.horizontal` a row divider dragged up and down.
public init(_ axis: Axis = .vertical, onDrag: @escaping (Double) -> Void, onEnd: @escaping () -> Void = {}) {
@@ -23,44 +22,117 @@ public struct Splitter: View {
.fill(isHovered || isDragging ? Palette.amber : Palette.raised)
.frame(width: axis == .vertical ? Metrics.hairline : nil, height: axis == .horizontal ? Metrics.hairline : nil)
.overlay {
Color.clear
SplitterHandle(axis: axis, onHover: { isHovered = $0 }, onDragging: { isDragging = $0 }, onDrag: onDrag, onEnd: onEnd)
.frame(width: axis == .vertical ? Metrics.splitterHitArea : nil,
height: axis == .horizontal ? Metrics.splitterHitArea : nil)
.contentShape(Rectangle())
.onHover(perform: hover)
.gesture(drag)
}
.zIndex(5)
.animation(Metrics.smallControlTransition, value: isHovered || isDragging)
}
}
private var drag: some Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
let position = axis == .vertical ? value.translation.width : value.translation.height
if !isDragging {
isDragging = true
last = 0
}
onDrag(Double(position - last))
last = position
}
.onEnded { _ in
isDragging = false
last = 0
if !isHovered { NSCursor.pop() }
onEnd()
}
/// The splitter's hit area as an AppKit view, so it owns its resize cursor instead of sharing a cursor stack.
private struct SplitterHandle: NSViewRepresentable {
var axis: Axis
var onHover: (Bool) -> Void
var onDragging: (Bool) -> Void
var onDrag: (Double) -> Void
var onEnd: () -> Void
func makeNSView(context: Context) -> SplitterHandleView {
let view = SplitterHandleView()
updateNSView(view, context: context)
return view
}
private func hover(_ inside: Bool) {
guard inside != isHovered else { return }
isHovered = inside
if isDragging { return }
if inside {
(axis == .vertical ? NSCursor.resizeLeftRight : NSCursor.resizeUpDown).push()
} else {
NSCursor.pop()
}
func updateNSView(_ view: SplitterHandleView, context: Context) {
view.axis = axis
view.onHover = onHover
view.onDragging = onDragging
view.onDrag = onDrag
view.onEnd = onEnd
}
}
final class SplitterHandleView: NSView {
var axis: Axis = .vertical {
didSet { if axis != oldValue { window?.invalidateCursorRects(for: self) } }
}
var onHover: (Bool) -> Void = { _ in }
var onDragging: (Bool) -> Void = { _ in }
var onDrag: (Double) -> Void = { _ in }
var onEnd: () -> Void = {}
private var dragStart: NSPoint?
private var last: CGFloat = 0
private var cursor: NSCursor {
axis == .vertical ? .resizeLeftRight : .resizeUpDown
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
override func resetCursorRects() {
addCursorRect(bounds, cursor: cursor)
}
override func updateTrackingAreas() {
super.updateTrackingAreas()
trackingAreas.forEach(removeTrackingArea)
addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseEnteredAndExited, .cursorUpdate, .activeInActiveApp, .inVisibleRect],
owner: self))
}
override func cursorUpdate(with event: NSEvent) {
cursor.set()
}
override func mouseEntered(with event: NSEvent) {
onHover(true)
cursor.set()
}
override func mouseExited(with event: NSEvent) {
guard dragStart == nil else { return }
onHover(false)
}
/// Cursor rects stay off for the whole drag: the columns resize under the pointer and would rebuild their I-beam.
override func mouseDown(with event: NSEvent) {
dragStart = event.locationInWindow
last = 0
window?.disableCursorRects()
cursor.set()
onDragging(true)
}
override func mouseDragged(with event: NSEvent) {
guard let dragStart else { return }
cursor.set()
let point = event.locationInWindow
let position = axis == .vertical ? point.x - dragStart.x : dragStart.y - point.y
onDrag(Double(position - last))
last = position
}
override func mouseUp(with event: NSEvent) {
guard dragStart != nil else { return }
let inside = bounds.contains(convert(event.locationInWindow, from: nil))
(inside ? cursor : NSCursor.arrow).set()
endDrag()
onHover(inside)
onEnd()
}
override func viewWillMove(toWindow newWindow: NSWindow?) {
if dragStart != nil { endDrag() }
super.viewWillMove(toWindow: newWindow)
}
private func endDrag() {
dragStart = nil
last = 0
onDragging(false)
window?.enableCursorRects()
window?.resetCursorRects()
}
}
@@ -1,75 +0,0 @@
import SwiftUI
/// A title-bar toggle: Sans 12 label plus keycap. Off has no fill; on gets the amber tint and an amber keycap border;
/// `muted` is for a toggle that is off by meaning (hidden files), where label and keycap step back to text-4.
public struct ToolbarToggle: View {
var label: String
var keys: String
var isOn: Bool
var isMuted: Bool
var action: () -> Void
@State private var isHovered = false
public init(_ label: String, keys: String, isOn: Bool, muted: Bool = false, action: @escaping () -> Void) {
self.label = label
self.keys = keys
self.isOn = isOn
isMuted = muted
self.action = action
}
public var body: some View {
Button(action: action) {
HStack(spacing: 8) {
Text(label).typeRole(isOn ? Typography.toolbarLabelOn : Typography.toolbarLabel)
Keycap(keys, style: isOn ? .active : isMuted ? .muted : .normal)
}
.foregroundStyle(labelColor)
.padding(Metrics.toolbarPadding)
.background(fill, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onHover { isHovered = $0 }
.animation(Metrics.smallControlTransition, value: isHovered)
.animation(Metrics.smallControlTransition, value: isOn)
}
private var labelColor: Color {
if isOn { return Palette.text1 }
if isMuted { return isHovered ? Palette.text3 : Palette.text4 }
return isHovered ? Palette.text1 : Palette.text3
}
private var fill: Color {
if isOn { return Palette.amberTint }
return isHovered && !isMuted ? Palette.hover : .clear
}
}
/// The icon-only title-bar control (the `?`): a 26pt square with a hairline border.
public struct ToolbarIconButton: View {
var glyph: String
var action: () -> Void
@State private var isHovered = false
public init(_ glyph: String, action: @escaping () -> Void) {
self.glyph = glyph
self.action = action
}
public var body: some View {
Button(action: action) {
Text(glyph)
.typeRole(Typography.keycap)
.foregroundStyle(isHovered ? Palette.text1 : Palette.text4)
.frame(width: Metrics.toolbarIconButton, height: Metrics.toolbarIconButton)
.background(isHovered ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onHover { isHovered = $0 }
.animation(Metrics.smallControlTransition, value: isHovered)
}
}
+33 -13
View File
@@ -19,17 +19,32 @@ public struct Tooltip: View {
}
public var body: some View {
text
.typeRole(Typography.tooltip)
.foregroundStyle(Palette.text2)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
.padding(.horizontal, 10)
.padding(.vertical, 8)
.frame(maxWidth: Metrics.tooltipMaxWidth, alignment: .leading)
.fixedSize()
.background(Palette.raised, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.tooltipBorder, lineWidth: Metrics.hairline))
CappedWidth(maxWidth: Metrics.tooltipMaxWidth) {
text
.typeRole(Typography.tooltip)
.foregroundStyle(Palette.text2)
.multilineTextAlignment(.leading)
.padding(.horizontal, 10)
.padding(.vertical, 8)
}
.background(Palette.raised, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.tooltipBorder, lineWidth: Metrics.hairline))
}
}
/// Sizes its content to its ideal width up to `maxWidth`, wrapping and growing taller beyond it, whatever is proposed.
/// `frame(maxWidth:)` under `fixedSize()` measures a wrapped text at its one-line height, so the text overflows the box.
private struct CappedWidth: Layout {
var maxWidth: CGFloat
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
guard let content = subviews.first else { return .zero }
let ideal = content.sizeThatFits(.unspecified)
return ideal.width <= maxWidth ? ideal : content.sizeThatFits(ProposedViewSize(width: maxWidth, height: nil))
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
subviews.first?.place(at: bounds.origin, anchor: .topLeading, proposal: ProposedViewSize(bounds.size))
}
}
@@ -54,18 +69,23 @@ struct TooltipModifier: ViewModifier {
}
.simultaneousGesture(TapGesture().onEnded { pending?.cancel(); isShown = false })
.overlay(alignment: Alignment(horizontal: edge, vertical: .bottom)) {
// A zero-height frame hangs the tip from the host's bottom edge; an explicit `.bottom`
// alignment guide is ignored here and left the tip covering the host.
if isShown {
Tooltip(text)
.alignmentGuide(.bottom) { $0[.top] - 8 }
.frame(height: 0, alignment: .top)
.offset(y: 8)
.allowsHitTesting(false)
}
}
.zIndex(isShown ? 1 : 0)
}
}
extension View {
/// Shows a design tooltip 350ms after the pointer rests on the view, 8pt below it.
/// The host must sit above its neighbours (`zIndex`) so the tip is not drawn under them.
/// The host lifts itself above its siblings while the tip shows; its container must still sit above
/// the views below it (`zIndex`), as the title bar does over the columns.
public func tip(_ text: Text, edge: HorizontalAlignment = .leading) -> some View {
modifier(TooltipModifier(text: text, edge: edge))
}
@@ -284,7 +284,7 @@ final class CodeEditorController: NSObject, NSTextViewDelegate, NSLayoutManagerD
private func applyWrap(_ on: Bool) {
guard wrap != on else { return }
wrap = on
scrollView.hasHorizontalScroller = !on
scrollView.hasHorizontalScroller = false
textView.isHorizontallyResizable = !on
container.widthTracksTextView = on
textView.autoresizingMask = on ? [.width] : []
+1 -1
View File
@@ -1,7 +1,7 @@
import AppKit
/// The NSTextView that holds the code. It only forwards gestures; `CodeEditorController` decides.
final class CodeTextView: NSTextView {
final class CodeTextView: PointerBoundTextView {
weak var controller: CodeEditorController?
/// Pointer travel that still counts as a click and not as a text selection.
+2 -1
View File
@@ -33,7 +33,8 @@ private struct EditorWorkspace: View {
if let path = editor.activePath {
let presentation = editor.presentation(for: path)
EditorBar(editor: editor, presentation: presentation)
EditorPane(editor: editor, presentation: presentation, fontScale: model.layout.textScale)
EditorPane(editor: editor, presentation: presentation, fontScale: model.layout.textScale,
isColumnShown: model.layout.isVisible(.editor))
} else {
EditorBar()
EditorEmptyState()
+3 -1
View File
@@ -8,6 +8,8 @@ struct EditorPane: View {
let presentation: EditorPresentation
/// View → Zoom.
var fontScale: CGFloat = 1
/// False while the File pane toggle hides the column: the code view then takes no focus or select-all.
var isColumnShown = true
var body: some View {
let path = presentation.path
@@ -15,7 +17,7 @@ struct EditorPane: View {
ZStack {
// Kept alive while hidden, so a trip to Preview keeps each file's undo history and colours.
if presentation.kind == .text {
CodeEditorView(configuration: configuration(path, isShown: showsCode), actions: actions)
CodeEditorView(configuration: configuration(path, isShown: showsCode && isColumnShown), actions: actions)
.opacity(showsCode ? 1 : 0)
.allowsHitTesting(showsCode)
}
+11 -10
View File
@@ -7,7 +7,6 @@ public struct PassOnPanel: View {
let insert: (String) -> Void
let cancel: () -> Void
@State private var note = ""
@FocusState private var focused: Bool
public init(request: PassOnRequest, insert: @escaping (String) -> Void, cancel: @escaping () -> Void) {
self.request = request
@@ -42,14 +41,8 @@ public struct PassOnPanel: View {
Spacer()
EscChip()
}
TextField("", text: $note, prompt: Text("Add a note (optional)…").foregroundStyle(Palette.text4))
.textFieldStyle(.plain)
.typeRole(TypeRole(.monoRegular, 13))
.foregroundStyle(Palette.text1)
.focused($focused)
.onSubmit { insert(composed) }
.onExitCommand(perform: cancel)
.padding(.horizontal, 10)
OverlayCommandField(text: $note, placeholder: "Add a note (optional)…", font: TypeRole(.monoRegular, 13).nsFont,
initialSelection: nil, horizontalInset: 10, onKey: handle)
.frame(height: 38)
.background(Palette.editor, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).stroke(Palette.amber, lineWidth: Metrics.accentRule))
@@ -68,7 +61,15 @@ public struct PassOnPanel: View {
.background(Palette.panel, in: RoundedRectangle(cornerRadius: Metrics.radiusMedium))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusMedium).stroke(Palette.raised, lineWidth: Metrics.hairline))
.shadow(color: Palette.menuShadow, radius: Metrics.menuShadowRadius, y: Metrics.menuShadowY)
.onAppear { focused = true }
}
private func handle(_ key: OverlayKey) -> Bool {
switch key {
case .enter: insert(composed)
case .escape: cancel()
default: return false
}
return true
}
@ViewBuilder
@@ -84,8 +84,7 @@ struct NamePromptOverlay: View {
EscChip()
}
OverlayCommandField(text: $name, placeholder: text.placeholder, font: TypeRole(.monoRegular, 13).nsFont,
initialSelection: text.initialSelection, onKey: handle)
.padding(.horizontal, 10)
initialSelection: text.initialSelection, horizontalInset: 10, onKey: handle)
.frame(height: 38)
.background(Palette.editor, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.focusRing(true)
+2 -1
View File
@@ -62,6 +62,7 @@ private struct NoteEditor: NSViewRepresentable {
textView.autoresizingMask = [.width]
textView.textContainer?.widthTracksTextView = true
textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
textView.fillsClipView = true
scroll.documentView = textView
let role = Typography.note
let paragraph = NSMutableParagraphStyle()
@@ -119,7 +120,7 @@ private struct NoteEditor: NSViewRepresentable {
}
/// Catches ⌘P before the menu bar's ⌘P (push) and draws the placeholder.
private final class NoteTextView: NSTextView {
private final class NoteTextView: PointerBoundTextView {
var onKey: (OverlayKey) -> Bool = { _ in false }
var placeholder = ""
+64 -4
View File
@@ -39,17 +39,20 @@ enum OverlayKey: Equatable {
}
/// A borderless single-line field that hands navigation keys to the overlay before the text system sees them.
/// It fills the frame it is given and centres the text in it, so the whole box takes the I-beam and the click.
struct OverlayCommandField: NSViewRepresentable {
@Binding var text: String
var placeholder: String
var font: NSFont
/// nil selects the whole text on focus, so typing replaces a seeded query.
var initialSelection: NSRange?
/// Space between the box's edges and the text.
var horizontalInset: CGFloat = 0
var onKey: (OverlayKey) -> Bool
func makeCoordinator() -> Coordinator { Coordinator(self) }
func makeNSView(context: Context) -> NSTextField {
func makeNSView(context: Context) -> CommandFieldBox {
let field = FocusingTextField()
field.isBordered = false
field.drawsBackground = false
@@ -65,12 +68,19 @@ struct OverlayCommandField: NSViewRepresentable {
field.cell?.isScrollable = true
field.cell?.wraps = false
field.initialSelection = initialSelection
return field
return CommandFieldBox(field: field, inset: horizontalInset)
}
func updateNSView(_ field: NSTextField, context: Context) {
func updateNSView(_ box: CommandFieldBox, context: Context) {
context.coordinator.parent = self
if field.stringValue != text { field.stringValue = text }
if box.field.stringValue != text { box.field.stringValue = text }
}
func sizeThatFits(_ proposal: ProposedViewSize, nsView box: CommandFieldBox, context: Context) -> CGSize? {
let fieldHeight = box.field.intrinsicContentSize.height
let width = proposal.width.flatMap { $0.isFinite ? $0 : nil } ?? max(box.field.intrinsicContentSize.width, 0) + 2 * box.inset
let height = proposal.height.flatMap { $0.isFinite ? max($0, fieldHeight) : nil } ?? fieldHeight
return CGSize(width: width, height: height)
}
final class Coordinator: NSObject, NSTextFieldDelegate {
@@ -92,6 +102,38 @@ struct OverlayCommandField: NSViewRepresentable {
}
}
/// The box around an `OverlayCommandField`: an I-beam over all of it, and a click anywhere focuses the field.
final class CommandFieldBox: NSView {
let field: NSTextField
let inset: CGFloat
init(field: NSTextField, inset: CGFloat) {
self.field = field
self.inset = inset
super.init(frame: .zero)
addSubview(field)
}
required init?(coder: NSCoder) {
fatalError("CommandFieldBox is built in code")
}
override func layout() {
super.layout()
let height = min(field.intrinsicContentSize.height, bounds.height)
field.frame = NSRect(x: inset, y: ((bounds.height - height) / 2).rounded(), width: max(0, bounds.width - 2 * inset), height: height)
}
override func resetCursorRects() {
addCursorRect(bounds, cursor: .iBeam)
}
override func mouseDown(with event: NSEvent) {
guard field.currentEditor() == nil else { return }
window?.makeFirstResponder(field)
}
}
/// An invisible first responder that forwards the overlay keys and swallows the ones it handles.
struct OverlayKeyCatcher: NSViewRepresentable {
var onKey: (OverlayKey) -> Bool
@@ -138,6 +180,11 @@ private final class FocusingTextField: NSTextField {
var initialSelection: NSRange?
private var focused = false
override class var cellClass: AnyClass? {
get { PointerBoundFieldCell.self }
set {}
}
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
guard !focused, window != nil else { return }
@@ -152,3 +199,16 @@ private final class FocusingTextField: NSTextField {
}
}
}
/// Edits through a PointerBoundTextView instead of the window's shared field editor, which sets the I-beam on every mouse move.
private final class PointerBoundFieldCell: NSTextFieldCell {
private lazy var editor: PointerBoundTextView = {
let editor = PointerBoundTextView()
editor.isFieldEditor = true
return editor
}()
override func fieldEditor(for controlView: NSView) -> NSTextView? {
editor
}
}
@@ -173,7 +173,6 @@ struct SearchOverlay: View {
ForEach(group.rows) { row in
let selected = model.column == .project && model.projectSelection == row.index
hitLine(row.hit, selected: selected)
.id(row.index)
.onHover { inside in if inside { hover(.project, row: row.index) } }
.onTapGesture { open(SearchModel.Target(path: row.path, line: row.hit.line)) }
}
@@ -181,7 +180,10 @@ struct SearchOverlay: View {
}
.padding(.bottom, 12)
}
.onChange(of: model.projectSelection) { _, row in proxy.scrollTo(row) }
// Scrolls by the ForEach id: an extra `.id` on a row makes the LazyVStack keep stale rows.
.onChange(of: model.projectSelection) { _, row in
if model.hitRows.indices.contains(row) { proxy.scrollTo(model.hitRows[row].id) }
}
}
}
}
@@ -238,13 +240,14 @@ struct SearchOverlay: View {
ForEach(Array(matches.enumerated()), id: \.element.path) { index, match in
let selected = model.column == .files && model.fileSelection == index
fileRow(match, selected: selected)
.id(index)
.onHover { inside in if inside { hover(.files, row: index) } }
.onTapGesture { open(SearchModel.Target(path: match.path, line: nil)) }
}
}
}
.onChange(of: model.fileSelection) { _, row in proxy.scrollTo(row) }
.onChange(of: model.fileSelection) { _, row in
if matches.indices.contains(row) { proxy.scrollTo(matches[row].path) }
}
}
}
}
+3 -1
View File
@@ -74,8 +74,10 @@ public enum Command: Equatable, Sendable {
// MARK: Layout and focus
/// ⌘G
/// ⌘G: the Source Control pane toggle.
case toggleGit
/// A title-bar pane toggle: shows or hides one column.
case togglePane(Panel)
/// ⌘L
case toggleAutoFit
/// ⌘.
+10 -1
View File
@@ -66,10 +66,19 @@ struct HelderCommands: Commands {
.keyboardShortcut("r", modifiers: .command)
.disabled(workspace?.root == nil)
Divider()
Button(workspace?.layout.gitVisible == false ? "Show Source Control" : "Hide Source Control") {
Button(workspace?.layout.isVisible(.sourceControl) == false ? "Show Source Control" : "Hide Source Control") {
workspace?.perform(.toggleGit)
}
.keyboardShortcut("g", modifiers: .command)
Button(workspace?.layout.isVisible(.explorer) == false ? "Show Explorer" : "Hide Explorer") {
workspace?.perform(.togglePane(.explorer))
}
Button(workspace?.layout.isVisible(.editor) == false ? "Show File" : "Hide File") {
workspace?.perform(.togglePane(.editor))
}
Button(workspace?.layout.isVisible(.terminal) == false ? "Show Claude" : "Hide Claude") {
workspace?.perform(.togglePane(.terminal))
}
Button(workspace?.layout.fluid == false ? "Fluid Column Widths" : "Lock Column Widths") {
workspace?.perform(.toggleAutoFit)
}
+79 -33
View File
@@ -1,12 +1,13 @@
import HelderCore
import SwiftUI
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, and the toolbar.
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, the pane toggles
/// centred on the window, and the toolbar.
struct TitleBarView: View {
let model: WorkspaceModel
var body: some View {
HStack(spacing: Metrics.titleBarGap) {
TitleBarLayout(leading: model.layout.isFullScreen ? 14 : Metrics.trafficLightInset, trailing: 14, gap: Metrics.titleBarGap) {
HStack(alignment: .firstTextBaseline, spacing: Metrics.titleClusterGap) {
Wordmark()
ProjectName(name: model.name) { model.perform(.openFolder) }
@@ -19,16 +20,45 @@ struct TitleBarView: View {
.fixedSize()
Breadcrumb(path: model.editor?.activePath, isDirty: model.editor.map { e in e.activePath.map(e.isDirty) ?? false } ?? false)
.frame(maxWidth: .infinity, alignment: .leading)
PaneToggles(model: model)
TitleToolbar(model: model)
}
.padding(.leading, model.layout.isFullScreen ? 14 : Metrics.trafficLightInset)
.padding(.trailing, 14)
.frame(height: Metrics.titleBar)
.background(Palette.panel)
.hairline(.bottom)
}
}
/// Lays out the four title-bar parts: the pane toggles sit on the window's centre, and the breadcrumb
/// gets only the room left of them. The toggles move left only when the toolbar would run into them.
private struct TitleBarLayout: Layout {
var leading: CGFloat
var trailing: CGFloat
var gap: CGFloat
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
CGSize(width: proposal.width ?? 0, height: proposal.height ?? Metrics.titleBar)
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
guard subviews.count == 4 else { return }
let (cluster, crumb, toggles, toolbar) = (subviews[0], subviews[1], subviews[2], subviews[3])
let y = bounds.midY
let clusterSize = cluster.sizeThatFits(.unspecified)
let togglesSize = toggles.sizeThatFits(.unspecified)
let toolbarSize = toolbar.sizeThatFits(.unspecified)
let clusterX = bounds.minX + leading
let toolbarX = bounds.maxX - trailing - toolbarSize.width
let togglesX = min(bounds.midX - togglesSize.width / 2, toolbarX - gap - togglesSize.width)
let crumbX = clusterX + clusterSize.width + gap
cluster.place(at: CGPoint(x: clusterX, y: y), anchor: .leading, proposal: ProposedViewSize(clusterSize))
toggles.place(at: CGPoint(x: togglesX, y: y), anchor: .leading, proposal: ProposedViewSize(togglesSize))
toolbar.place(at: CGPoint(x: toolbarX, y: y), anchor: .leading, proposal: ProposedViewSize(toolbarSize))
crumb.place(at: CGPoint(x: crumbX, y: y), anchor: .leading,
proposal: ProposedViewSize(width: max(0, togglesX - gap - crumbX), height: bounds.height))
}
}
private struct ProjectName: View {
let name: String
let action: () -> Void
@@ -58,7 +88,7 @@ private struct Breadcrumb: View {
ForEach(Array(segments.enumerated()), id: \.offset) { index, segment in
if index > 0 { Text("›").foregroundStyle(Palette.text4) }
if index == segments.count - 1 {
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1)
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1).layoutPriority(1)
} else {
Text(segment).foregroundStyle(Palette.text4)
}
@@ -76,42 +106,58 @@ private struct Breadcrumb: View {
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N · Git ⌘G · `?`, each with a tooltip that names its state.
/// Git · Explorer · File · Claude: one toggle per column. Hiding a column keeps everything inside it.
private struct PaneToggles: View {
let model: WorkspaceModel
var body: some View {
ButtonGroup([
toggle("Git", .sourceControl, column: "Source Control"),
toggle("Explorer", .explorer, column: "Explorer"),
toggle("File", .editor, column: "File"),
toggle("Claude", .terminal, column: "Claude"),
])
}
private func toggle(_ label: String, _ panel: Panel, column: String) -> GroupItem {
let shown = model.layout.isVisible(panel)
let tip = shown
? Tooltip.stated(column + " column: ", "shown", ". Click to hide it.")
: Tooltip.stated(column + " column: ", "hidden", ". Click to show it.")
return GroupItem(label, kind: .toggle(isOn: shown), tip: tip) {
model.perform(.togglePane(panel))
}
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N, then `?`. Search and Note are actions; Fluid and Hidden toggle.
private struct TitleToolbar: View {
let model: WorkspaceModel
var body: some View {
let layout = model.layout
let overlay = model.overlay.current
HStack(spacing: Metrics.toolbarGap) {
ToolbarToggle("Search", keys: "⌘F", isOn: isSearch(overlay)) { model.perform(.showSearch(seed: "")) }
.tip("Search the open file, the project and the file names.", edge: .trailing)
ToolbarToggle("Fluid", keys: "⌘L", isOn: layout.fluid) { model.perform(.toggleAutoFit) }
.tip(layout.fluid
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid."),
edge: .trailing)
ToolbarToggle("Hidden", keys: "⌘.", isOn: layout.showHidden, muted: !layout.showHidden) { model.perform(.toggleHidden) }
.tip(layout.showHidden
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them."),
edge: .trailing)
ToolbarToggle("Note", keys: "⌘N", isOn: overlay == .note) { model.perform(.showNote) }
.tip("Project note (.notes.txt) — kept next to this project.", edge: .trailing)
ToolbarToggle("Git", keys: "⌘G", isOn: layout.gitVisible) { model.perform(.toggleGit) }
.tip(layout.gitVisible
? Tooltip.stated("Source Control column: ", "shown", ". Click to hide it.")
: Tooltip.stated("Source Control column: ", "hidden", ". Click to show it."),
edge: .trailing)
HStack(spacing: Metrics.toolbarIconGap) {
ButtonGroup([
GroupItem("Search", keys: "⌘F", kind: .action,
tip: Text("Search the open file, the project and the file names.")) { model.perform(.showSearch(seed: "")) },
GroupItem("Fluid", keys: "⌘L", kind: .toggle(isOn: layout.fluid),
tip: layout.fluid
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid.")) {
model.perform(.toggleAutoFit)
},
GroupItem("Hidden", keys: "⌘.", kind: .toggle(isOn: layout.showHidden),
tip: layout.showHidden
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them.")) {
model.perform(.toggleHidden)
},
GroupItem("Note", keys: "⌘N", kind: .action,
tip: Text("Project note (.notes.txt) — kept next to this project.")) { model.perform(.showNote) },
], tipEdge: .trailing)
ToolbarIconButton("?") { model.perform(.showShortcuts) }
.padding(.leading, 6)
.tip("Keyboard shortcuts.", edge: .trailing)
}
.fixedSize()
}
private func isSearch(_ overlay: Overlay) -> Bool {
if case .search = overlay { return true }
return false
}
}
+85 -9
View File
@@ -1,3 +1,5 @@
import AppKit
import HelderCore
import SwiftUI
/// The launcher without a project; with one, the title bar, four columns and status bar, overlays above.
@@ -37,35 +39,109 @@ struct WorkspaceView: View {
}
}
/// The four columns and their splitters. The agent column is keyed by the project so its terminals respawn on a switch.
/// The four columns and their splitters. Every column stays mounted: a pane toggle only hides it, so the
/// terminals, the editor buffer and the tree keep their state. The editor is the flex column; with the editor
/// hidden the agent column fills. The agent column is keyed by the project so its terminals respawn on a switch.
private struct Columns: View {
let model: WorkspaceModel
/// The editor's last shown width, kept while it is hidden so its text does not re-wrap.
@State private var editorWidth = Metrics.minEditorWidth
var body: some View {
let layout = model.layout
let v = layout.visibility
let agentFills = v.agent && !v.editor
let hiddenEditorWidth = max(editorWidth, Metrics.minEditorWidth)
HStack(spacing: 0) {
if layout.gitVisible {
SourceControlColumn(model: model)
.frame(width: layout.widths.sourceControl)
.refreshFlash(model.refreshTick)
Splitter(onDrag: { layout.dragSourceControl(by: $0) }, onEnd: layout.endDrag)
}
SourceControlColumn(model: model)
.frame(width: layout.widths.sourceControl)
.refreshFlash(model.refreshTick)
.pane(shown: v.sourceControl)
Splitter(onDrag: { layout.dragSourceControl(by: $0) }, onEnd: layout.endDrag)
.pane(shown: v.sourceControl && (v.explorer || v.editor || v.agent))
ExplorerColumn(model: model)
.frame(width: layout.widths.explorer)
.refreshFlash(model.refreshTick)
.pane(shown: v.explorer)
Splitter(onDrag: { layout.dragExplorer(by: $0) }, onEnd: layout.endDrag)
.pane(shown: v.explorer && (v.editor || v.agent))
EditorColumn(model: model)
.frame(minWidth: Metrics.minEditorWidth, maxWidth: .infinity)
.frame(minWidth: v.editor ? Metrics.minEditorWidth : hiddenEditorWidth, maxWidth: v.editor ? .infinity : hiddenEditorWidth)
.onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in
if v.editor { editorWidth = width }
}
.refreshFlash(model.refreshTick)
.pane(shown: v.editor)
Splitter(onDrag: { layout.dragAgent(by: $0) }, onEnd: layout.endDrag)
.pane(shown: v.editor && v.agent)
AgentColumn(model: model)
.frame(width: layout.widths.agent)
.frame(minWidth: agentFills ? Metrics.minEditorWidth : layout.widths.agent,
maxWidth: agentFills ? .infinity : layout.widths.agent)
.id(model.root)
.pane(shown: v.agent)
if !v.editor && !v.agent {
Spacer(minLength: 0)
}
}
.background(Palette.editor)
.background(HiddenPaneFocusGuard(visibility: v))
.clipped()
}
}
/// Hides a column without unmounting it. The hidden column keeps its own width, so a terminal never
/// resizes to nothing, and is parked outside the window, so its AppKit views own no pixels, clicks or cursor.
private struct PaneVisibility: ViewModifier {
static let parkedOffset: CGFloat = 100_000
let shown: Bool
func body(content: Content) -> some View {
content
.frame(width: shown ? nil : 0, alignment: .leading)
.opacity(shown ? 1 : 0)
.allowsHitTesting(shown)
.accessibilityHidden(!shown)
.offset(x: shown ? 0 : Self.parkedOffset)
}
}
extension View {
fileprivate func pane(shown: Bool) -> some View {
modifier(PaneVisibility(shown: shown))
}
}
/// When a column is hidden while it holds the keyboard (a terminal, the code, the commit box), the window
/// takes the keyboard back, so typing never lands in a pane nobody can see.
private struct HiddenPaneFocusGuard: NSViewRepresentable {
let visibility: ColumnVisibility
func makeNSView(context: Context) -> GuardView {
GuardView()
}
func updateNSView(_ view: GuardView, context: Context) {
view.visibility = visibility
}
final class GuardView: NSView {
var visibility: ColumnVisibility? {
didSet {
guard let oldValue, oldValue != visibility else { return }
DispatchQueue.main.async { [weak self] in self?.releaseParkedResponder() }
}
}
override func hitTest(_ point: NSPoint) -> NSView? { nil }
private func releaseParkedResponder() {
guard let window, let responder = window.firstResponder as? NSView, let content = window.contentView else { return }
let view = responder.enclosingScrollView ?? responder
if view.convert(view.bounds, to: nil).minX >= content.bounds.maxX { window.makeFirstResponder(nil) }
}
}
}
/// ⌘R lightens a column for a moment and lets it settle back; each new tick replays it.
private struct RefreshFlash: ViewModifier {
let tick: Int
@@ -167,6 +167,7 @@ struct CommitTextView: NSViewRepresentable {
textView.isHorizontallyResizable = false
textView.autoresizingMask = [.width]
textView.textContainer?.widthTracksTextView = true
textView.fillsClipView = true
let paragraph = NSMutableParagraphStyle()
paragraph.minimumLineHeight = 18
paragraph.maximumLineHeight = 18
@@ -210,7 +211,7 @@ struct CommitTextView: NSViewRepresentable {
}
}
final class CommitNSTextView: NSTextView {
final class CommitNSTextView: PointerBoundTextView {
var onCommit: (() -> Void)?
var onFocusChange: ((Bool) -> Void)?
+67 -19
View File
@@ -18,13 +18,37 @@ public struct ColumnLayoutSnapshot: Codable, Sendable, Equatable {
public var agentWidth: Double
public var fluid: Bool
public var gitVisible: Bool
public var explorerVisible: Bool
public var fileVisible: Bool
public var claudeVisible: Bool
public init(sourceControlWidth: Double, explorerWidth: Double, agentWidth: Double, fluid: Bool, gitVisible: Bool) {
public init(sourceControlWidth: Double, explorerWidth: Double, agentWidth: Double, fluid: Bool,
visibility: ColumnVisibility = .all) {
self.sourceControlWidth = sourceControlWidth
self.explorerWidth = explorerWidth
self.agentWidth = agentWidth
self.fluid = fluid
self.gitVisible = gitVisible
gitVisible = visibility.sourceControl
explorerVisible = visibility.explorer
fileVisible = visibility.editor
claudeVisible = visibility.agent
}
/// Older snapshots only know `gitVisible`; a missing flag means shown.
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
sourceControlWidth = try c.decode(Double.self, forKey: .sourceControlWidth)
explorerWidth = try c.decode(Double.self, forKey: .explorerWidth)
agentWidth = try c.decode(Double.self, forKey: .agentWidth)
fluid = try c.decode(Bool.self, forKey: .fluid)
gitVisible = try c.decodeIfPresent(Bool.self, forKey: .gitVisible) ?? true
explorerVisible = try c.decodeIfPresent(Bool.self, forKey: .explorerVisible) ?? true
fileVisible = try c.decodeIfPresent(Bool.self, forKey: .fileVisible) ?? true
claudeVisible = try c.decodeIfPresent(Bool.self, forKey: .claudeVisible) ?? true
}
public var visibility: ColumnVisibility {
ColumnVisibility(sourceControl: gitVisible, explorer: explorerVisible, editor: fileVisible, agent: claudeVisible)
}
public static func key(root: String) -> String { "helder.layout:" + root }
@@ -71,8 +95,8 @@ public final class LayoutStore {
/// The agent pane's share of the right column; persisted across launches.
public private(set) var agentFraction: Double
public private(set) var windowWidth: Double = 1680
/// ⌘G: the Source Control column is shown.
public private(set) var gitVisible = true
/// The title bar's pane toggles; ⌘G flips Source Control.
public private(set) var visibility = ColumnVisibility.all
/// ⌘L: columns re-fit on resize and focus. A manual splitter drag turns this off.
public private(set) var fluid = true
/// ⌘.: dotfiles show in the tree and the search.
@@ -122,7 +146,7 @@ public final class LayoutStore {
activePanel = nil
focusZone = .neutral
let saved = persistence?.load(root: root)
gitVisible = saved?.gitVisible ?? true
visibility = saved?.visibility ?? .all
fluid = saved?.fluid ?? true
if let saved, !saved.fluid {
widths = ColumnWidths(sourceControl: clamp(saved.sourceControlWidth, ColumnLayout.sourceControlRange),
@@ -134,12 +158,32 @@ public final class LayoutStore {
public var snapshot: ColumnLayoutSnapshot {
ColumnLayoutSnapshot(sourceControlWidth: widths.sourceControl, explorerWidth: widths.explorer,
agentWidth: widths.agent, fluid: fluid, gitVisible: gitVisible)
agentWidth: widths.agent, fluid: fluid, visibility: visibility)
}
public func toggleGit() {
gitVisible.toggle()
if !gitVisible && activePanel == .sourceControl { activePanel = nil }
public func isVisible(_ panel: Panel) -> Bool {
switch panel {
case .sourceControl: visibility.sourceControl
case .explorer: visibility.explorer
case .editor: visibility.editor
case .terminal: visibility.agent
}
}
/// Shows or hides one column; a hidden column loses keyboard focus but keeps everything inside it.
public func togglePane(_ panel: Panel) {
setVisible(panel, !isVisible(panel))
}
public func setVisible(_ panel: Panel, _ visible: Bool) {
guard isVisible(panel) != visible else { return }
switch panel {
case .sourceControl: visibility.sourceControl = visible
case .explorer: visibility.explorer = visible
case .editor: visibility.editor = visible
case .terminal: visibility.agent = visible
}
if !visible && activePanel == panel { activePanel = nil }
refit()
save()
}
@@ -161,7 +205,7 @@ public final class LayoutStore {
/// Focus moves the fluid widths below 1600pt: the editor or the terminals get more room.
public func focus(_ panel: Panel) {
if panel == .sourceControl && !gitVisible { return }
guard isVisible(panel) else { return }
activePanel = panel
switch panel {
case .editor: focusZone = .editor
@@ -190,7 +234,7 @@ public final class LayoutStore {
/// The agent splitter sits on the column's left edge, so dragging right shrinks it.
public func dragAgent(by delta: Double) {
fluid = false
let maxWidth = ColumnLayout.maxAgentWidth(windowWidth: windowWidth, widths: widths, sourceControlVisible: gitVisible)
let maxWidth = ColumnLayout.maxAgentWidth(windowWidth: windowWidth, widths: widths, visible: visibility)
widths.agent = clamp(widths.agent - delta, ColumnLayout.minEditorWidth...maxWidth)
}
@@ -214,19 +258,22 @@ public final class LayoutStore {
/// The visible columns, left to right.
public var columns: [Panel] {
gitVisible ? Panel.allCases : [.explorer, .editor, .terminal]
Panel.allCases.filter(isVisible)
}
/// The horizontal extent of a column in window coordinates; nil for a hidden column.
/// The editor is the flex column; with the editor hidden the agent column fills the rest.
public func span(of panel: Panel) -> ClosedRange<Double>? {
guard isVisible(panel) else { return nil }
let splitter = ColumnLayout.splitterWidth
let sc = gitVisible ? widths.sourceControl + splitter : 0
let editorStart = sc + widths.explorer + splitter
let agentStart = max(editorStart, windowWidth - widths.agent)
let v = visibility
let explorerStart = v.sourceControl ? widths.sourceControl + splitter : 0
let flexStart = explorerStart + (v.explorer ? widths.explorer + splitter : 0)
let agentStart = v.editor ? max(flexStart, windowWidth - widths.agent) : flexStart
switch panel {
case .sourceControl: return gitVisible ? 0...widths.sourceControl : nil
case .explorer: return sc...(sc + widths.explorer)
case .editor: return editorStart...max(editorStart, agentStart - splitter)
case .sourceControl: return 0...widths.sourceControl
case .explorer: return explorerStart...(explorerStart + widths.explorer)
case .editor: return flexStart...max(flexStart, v.agent ? agentStart - splitter : windowWidth)
case .terminal: return agentStart...max(agentStart, windowWidth)
}
}
@@ -242,13 +289,14 @@ public final class LayoutStore {
/// The column `step` places left (−1) or right (+1) of `panel`, clamped at the ends. No focus counts as the editor.
public func neighbour(of panel: Panel?, step: Int) -> Panel {
let list = columns
guard !list.isEmpty else { return panel ?? .editor }
let index = list.firstIndex(of: panel ?? .editor) ?? list.firstIndex(of: .editor) ?? 0
return list[min(max(index + step, 0), list.count - 1)]
}
private func refit() {
var next = fluid ? ColumnLayout.fluid(windowWidth: windowWidth, focus: focusZone) : widths
next = ColumnLayout.fitted(next, windowWidth: windowWidth, sourceControlVisible: gitVisible)
next = ColumnLayout.fitted(next, windowWidth: windowWidth, visible: visibility)
if next != widths { widths = next }
}
+3 -2
View File
@@ -149,7 +149,8 @@ public final class WorkspaceModel {
case let .launcherSelect(index): launcher.select(index)
case .launcherActivate: activateLauncher()
case .toggleGit: layout.toggleGit()
case .toggleGit: layout.togglePane(.sourceControl)
case let .togglePane(panel): layout.togglePane(panel)
case .toggleAutoFit: layout.toggleFluid()
case .toggleHidden: layout.toggleHidden()
case let .focus(panel): focus(panel)
@@ -180,7 +181,7 @@ public final class WorkspaceModel {
guard let sourceControl else { return }
track { _ = await sourceControl.push() }
case .focusCommitMessage:
if !layout.gitVisible { layout.toggleGit() }
layout.setVisible(.sourceControl, true)
layout.focus(.sourceControl)
focusRequest = FocusRequest(.commitMessage)
@@ -18,6 +18,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle
super.init(frame: NSRect(x: 0, y: 0, width: 480, height: 320),
font: TerminalAppearance.font(store.config.terminal),
options: TerminalAppearance.options(store.config.terminal))
Self.arrowCursorUpdate
events.owner = self
processDelegate = events
appliedSettings = store.config.terminal
@@ -58,6 +59,20 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle
super.send(source: source, data: data)
}
/// ⌥← and ⌥→ jump by word (ESC b / ESC f, as Terminal.app does) while Option is not the Meta key.
override func interpretKeyEvents(_ events: [NSEvent]) {
if !optionAsMetaKey, events.count == 1, let event = events.first, event.type == .keyDown,
event.modifierFlags.intersection([.shift, .control, .option, .command]) == .option,
let key = event.charactersIgnoringModifiers?.unicodeScalars.first.map({ Int($0.value) }) {
switch key {
case NSLeftArrowFunctionKey: return send(EscapeSequences.emacsBack)
case NSRightArrowFunctionKey: return send(EscapeSequences.emacsForward)
default: break
}
}
super.interpretKeyEvents(events)
}
/// Selecting text copies it, in both panes.
override func selectionChanged(source: Terminal) {
super.selectionChanged(source: source)
@@ -87,6 +102,23 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle
return nil
}
// MARK: Pointer
/// The terminal shows the arrow, so SwiftTerm's I-beam rect is dropped; its `resetCursorRects` is not open.
override func addCursorRect(_ rect: NSRect, cursor object: NSCursor) {
guard object != .iBeam else { return }
super.addCursorRect(rect, cursor: object)
}
/// Gives this class its own `cursorUpdate:` that sets the arrow; Swift cannot override SwiftTerm's I-beam one,
/// which runs when an update reaches the pane through a subview or a neighbour's tracking area.
private static let arrowCursorUpdate: Void = {
let block: @convention(block) (AnyObject, NSEvent) -> Void = { _, _ in NSCursor.arrow.set() }
let selector = #selector(NSResponder.cursorUpdate(with:))
let types = method_getTypeEncoding(class_getInstanceMethod(NSView.self, selector)!)
class_addMethod(HelderTerminalView.self, selector, imp_implementationWithBlock(block), types)
}()
// MARK: Lifetime
/// Closing the window kills the child; moving the view between containers does not.
+8 -2
View File
@@ -62,8 +62,12 @@ public enum Metrics {
public static let titleBarGap: CGFloat = 18
public static let titleClusterGap: CGFloat = 10
public static let crumbGap: CGFloat = 7
public static let toolbarGap: CGFloat = 4
public static let toolbarPadding = EdgeInsets(top: 6, leading: 9, bottom: 6, trailing: 9)
/// A button inside a `ButtonGroup`: the pane toggles and the toolbar.
public static let groupButtonPadding = EdgeInsets(top: 6, leading: 10, bottom: 6, trailing: 10)
public static let groupButtonGap: CGFloat = 7
public static let groupButtonDot: CGFloat = 6
/// Between the toolbar group and the `?`.
public static let toolbarIconGap: CGFloat = 8
/// The `?` button: a square with a hairline border.
public static let toolbarIconButton: CGFloat = 26
public static let statusBarGap: CGFloat = 16
@@ -76,6 +80,8 @@ public enum Metrics {
// MARK: Overlays
public static let overlayInset: CGFloat = 34
/// The widest an `.inset` overlay grows; past it the card stays centred.
public static let insetOverlayMaxWidth: CGFloat = 1200
public static let contextMenuWidth: CGFloat = 320
public static let passOnWidth: CGFloat = 460
public static let launcherWidth: CGFloat = 520
+1 -1
View File
@@ -45,7 +45,7 @@ public enum Palette {
public static let amberSoft = Color(hex: 0xF0B476)
public static let amberTint = Color(hex: 0xE8913A, alpha: 0.10)
public static let focusRing = Color(hex: 0xE8913A, alpha: 0.22)
/// Border of an active toolbar toggle's keycap.
/// Border of a lit key in the symbol popup.
public static let amberKeycapBorder = Color(hex: 0xE8913A, alpha: 0.35)
/// Text on an amber fill: always ink, never white.
public static let ink = Color(hex: 0x171C22)
-1
View File
@@ -86,7 +86,6 @@ public enum Typography {
public static let segment = TypeRole(.sansRegular, 11)
public static let segmentOn = TypeRole(.sansMedium, 11)
public static let toolbarLabel = TypeRole(.sansRegular, 12)
public static let toolbarLabelOn = TypeRole(.sansMedium, 12)
public static let menuItem = TypeRole(.sansRegular, 13)
public static let menuItemHighlighted = TypeRole(.sansMedium, 13)
public static let note = TypeRole(.monoRegular, 14, lineHeight: 23.8)