adds schema view and schema generating command
This commit is contained in:
@@ -59,11 +59,21 @@ public struct KeyContext: Equatable, Sendable {
|
||||
public var gitViewOpen: Bool
|
||||
/// The keyboard sits in the Git view's console input, where ⌘↵ must not commit.
|
||||
public var inGitConsole: Bool
|
||||
/// The project is a Laravel app, so ⌘D has a Schema view to toggle.
|
||||
public var schemaAvailable: Bool
|
||||
/// The full-screen Schema view covers the columns, like the Git view.
|
||||
public var schemaViewOpen: Bool
|
||||
/// A table is selected in the Schema view; Esc clears it first.
|
||||
public var schemaHasSelection: Bool
|
||||
/// The keyboard sits in the Schema table search and it holds text; Esc clears it before closing the view.
|
||||
public var schemaSearchHasText: Bool
|
||||
|
||||
public init(hasProject: Bool = true, overlay: OverlayKind = .none, owner: KeyboardOwner = .workspace,
|
||||
hasTextSelection: Bool = false, editorTextSelection: TextSelectionInfo? = nil,
|
||||
hasEditorLineSelection: Bool = false, activePanel: Panel? = nil, focusZone: FocusZone = .neutral,
|
||||
recentFileCount: Int = 0, searchSeed: String = "", gitViewOpen: Bool = false, inGitConsole: Bool = false) {
|
||||
recentFileCount: Int = 0, searchSeed: String = "", gitViewOpen: Bool = false, inGitConsole: Bool = false,
|
||||
schemaAvailable: Bool = false, schemaViewOpen: Bool = false, schemaHasSelection: Bool = false,
|
||||
schemaSearchHasText: Bool = false) {
|
||||
self.hasProject = hasProject
|
||||
self.overlay = overlay
|
||||
self.owner = owner
|
||||
@@ -76,6 +86,10 @@ public struct KeyContext: Equatable, Sendable {
|
||||
self.searchSeed = searchSeed
|
||||
self.gitViewOpen = gitViewOpen
|
||||
self.inGitConsole = inGitConsole
|
||||
self.schemaAvailable = schemaAvailable
|
||||
self.schemaViewOpen = schemaViewOpen
|
||||
self.schemaHasSelection = schemaHasSelection
|
||||
self.schemaSearchHasText = schemaSearchHasText
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +119,8 @@ public enum KeyRoute: Equatable {
|
||||
|
||||
/// Maps a key press to a command. A key that a focused field or terminal needs is never taken:
|
||||
/// arrows, ↵, `?`, ⌘A and ⌘C/⌘←/⌘→ go to the field; ⌘O, ⌘R and ⇧⌘N are left to the menu bar.
|
||||
/// Esc closes the topmost layer: an overlay, then the Git view, else it reaches the terminal.
|
||||
/// Esc closes the topmost layer: an overlay, then the Schema selection, search and view, then the Git view,
|
||||
/// else it reaches the terminal.
|
||||
public enum KeyRouter {
|
||||
public static func route(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
|
||||
if press.control || press.option { return .pass }
|
||||
@@ -116,7 +131,9 @@ public enum KeyRouter {
|
||||
case .diff(busy: true): return .pass
|
||||
case .none:
|
||||
if press.key == .escape {
|
||||
return context.gitViewOpen && !press.command ? .perform(.closeGitView) : .pass
|
||||
guard !press.command else { return .pass }
|
||||
if context.schemaViewOpen { return schemaEscape(context) }
|
||||
return context.gitViewOpen ? .perform(.closeGitView) : .pass
|
||||
}
|
||||
default: if press.key == .escape && !press.command { return .perform(.dismissOverlay) }
|
||||
}
|
||||
@@ -127,6 +144,7 @@ public enum KeyRouter {
|
||||
case .other: return .pass
|
||||
}
|
||||
|
||||
if context.schemaViewOpen { return schemaViewKey(press, context) }
|
||||
if context.gitViewOpen { return gitViewKey(press, context) }
|
||||
return press.command ? commandKey(press, context) : plainKey(press, context)
|
||||
}
|
||||
@@ -145,6 +163,25 @@ public enum KeyRouter {
|
||||
}
|
||||
}
|
||||
|
||||
private static func schemaEscape(_ context: KeyContext) -> KeyRoute {
|
||||
if context.schemaHasSelection { return .perform(.clearSchemaSelection) }
|
||||
if context.schemaSearchHasText { return .perform(.clearSchemaSearch) }
|
||||
return .perform(.closeSchemaView)
|
||||
}
|
||||
|
||||
/// Over the Schema view the columns' keys rest as over the Git view; ⌘↵ and ⌘C have nothing to act on.
|
||||
private static func schemaViewKey(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
|
||||
guard press.command else {
|
||||
return press.key == .character("?") && context.owner == .workspace ? .perform(.showShortcuts) : .pass
|
||||
}
|
||||
if press.shift { return commandKey(press, context) }
|
||||
switch press.key {
|
||||
case .character("a"), .character("c"): return .pass
|
||||
case let .character(c): return commandCharacter(c, context)
|
||||
default: return .pass
|
||||
}
|
||||
}
|
||||
|
||||
private static func launcherKey(_ press: KeyPress) -> KeyRoute {
|
||||
guard !press.shift else { return .pass }
|
||||
switch press.key {
|
||||
@@ -198,6 +235,7 @@ public enum KeyRouter {
|
||||
case "m": return .perform(.cycleMode)
|
||||
case "w": return .perform(.closeFileOrWindow)
|
||||
case "g": return .perform(.toggleGit)
|
||||
case "d": return context.schemaAvailable ? .perform(.toggleSchemaView) : .pass
|
||||
case "1": return .perform(.togglePane(.explorer))
|
||||
case "2": return .perform(.togglePane(.editor))
|
||||
case "3": return .perform(.togglePane(.terminal))
|
||||
|
||||
Reference in New Issue
Block a user