Files

109 lines
5.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import SwiftUI
public struct ShortcutRow: Equatable, Sendable {
/// Each element is one keycap.
public var keys: [String]
public var label: String
}
public struct ShortcutGroup: Equatable, Sendable {
public var title: String
public var rows: [ShortcutRow]
}
/// The keyboard reference the `?` overlay shows. Keep it in step with the keyboard routing.
public enum ShortcutCatalog {
public static let groups: [ShortcutGroup] = [
ShortcutGroup(title: "Navigate", rows: [
ShortcutRow(keys: ["⌘", "F"], label: "Search contents and names"),
ShortcutRow(keys: ["⌘", "↑↓"], label: "Move through a list"),
ShortcutRow(keys: ["↵"], label: "Open the selected item"),
ShortcutRow(keys: ["⌘", "←→"], label: "Column left or right"),
ShortcutRow(keys: ["↑↓"], label: "Explorer: move the row cursor"),
ShortcutRow(keys: ["⌘", "1"], label: "Explorer column on or off"),
ShortcutRow(keys: ["⌘", "2"], label: "File column on or off"),
ShortcutRow(keys: ["⌘", "3"], label: "Claude column on or off"),
ShortcutRow(keys: ["⇧", "⌘", "O"], label: "Open a recent project"),
ShortcutRow(keys: ["⌘", "O"], label: "Open a project folder"),
ShortcutRow(keys: ["⇧", "⌘", "N"], label: "Open a new window"),
ShortcutRow(keys: ["⌘", "click"], label: "PHP class: declaration and references"),
ShortcutRow(keys: ["?"], label: "This list of shortcuts"),
]),
ShortcutGroup(title: "Agent", rows: [
ShortcutRow(keys: ["⌘", "→"], label: "Pass the selection to the agent"),
]),
ShortcutGroup(title: "Git", rows: [
ShortcutRow(keys: ["⌘", "G"], label: "Open or close the Git view"),
ShortcutRow(keys: ["⌘", "C"], label: "Focus the commit message"),
ShortcutRow(keys: ["⌘", "↵"], label: "Commit the staged files"),
ShortcutRow(keys: ["⌘", "P"], label: "Push the current branch"),
]),
ShortcutGroup(title: "Schema", rows: [
ShortcutRow(keys: ["⌘", "D"], label: "Open or close Schema (Laravel apps)"),
ShortcutRow(keys: ["↵"], label: "Table search: centre the first match"),
]),
ShortcutGroup(title: "File", rows: [
ShortcutRow(keys: ["⌘", "S"], label: "Save this file"),
ShortcutRow(keys: ["⌘", "M"], label: "Markdown: code or rendered preview"),
ShortcutRow(keys: ["⌘", "W"], label: "Close this file, or the window when none is open"),
ShortcutRow(keys: ["⌘", "R"], label: "Re-read git and the files from disk"),
ShortcutRow(keys: ["⌘", "."], label: "Hidden files on or off"),
ShortcutRow(keys: ["⌘", "A"], label: "Select all in this pane"),
ShortcutRow(keys: ["⌘", "L"], label: "Fluid columns on or off"),
ShortcutRow(keys: ["⌘", "+"], label: "Zoom in"),
ShortcutRow(keys: ["⌘", "−"], label: "Zoom out"),
ShortcutRow(keys: ["⌘", "0"], label: "Actual size"),
ShortcutRow(keys: ["Esc"], label: "Close an overlay, then the Schema selection or view, then the Git view"),
]),
]
}
/// `?`: the keyboard reference, grouped NAVIGATE / AGENT / GIT / SCHEMA / FILE.
struct ShortcutsOverlay: View {
var onClose: () -> Void
var body: some View {
OverlayShell(.sized(width: 600), onDismiss: onClose) {
VStack(spacing: 0) {
OverlayHeader(systemImage: "questionmark.circle", title: "Keyboard shortcuts")
// Grows with its content, and scrolls only when the window is too short for it.
ViewThatFits(in: .vertical) {
list
ScrollView { list }
}
}
.background(OverlayKeyCatcher { key in
guard key == .escape else { return false }
onClose()
return true
})
}
}
private var list: some View {
VStack(alignment: .leading, spacing: 0) {
ForEach(Array(ShortcutCatalog.groups.enumerated()), id: \.offset) { index, group in
Text(group.title)
.typeRole(Typography.panelLabel)
.foregroundStyle(Palette.text4)
.padding(.top, index == 0 ? 0 : 16)
.padding(.bottom, 8)
ForEach(Array(group.rows.enumerated()), id: \.offset) { _, row in
HStack(spacing: 14) {
HStack(spacing: 4) {
ForEach(Array(row.keys.enumerated()), id: \.offset) { _, key in
Keycap(key).frame(minWidth: 22)
}
}
.frame(width: 92, alignment: .leading)
Text(row.label).typeRole(Typography.row).foregroundStyle(Palette.text2)
}
.padding(.vertical, 6)
}
}
}
.padding(EdgeInsets(top: 18, leading: 20, bottom: 22, trailing: 20))
.frame(maxWidth: .infinity, alignment: .leading)
}
}