adds nice git interface
This commit is contained in:
@@ -8,6 +8,7 @@ struct WindowBridge: NSViewRepresentable {
|
||||
/// Passed as values so a project switch re-runs `updateNSView`, which renames the window and the app.
|
||||
let title: String
|
||||
let hasProject: Bool
|
||||
let gitViewOpen: Bool
|
||||
|
||||
func makeCoordinator() -> WindowCoordinator {
|
||||
WindowCoordinator(model: model)
|
||||
@@ -21,6 +22,7 @@ struct WindowBridge: NSViewRepresentable {
|
||||
|
||||
func updateNSView(_ view: BridgeView, context: Context) {
|
||||
context.coordinator.updateTitle(title, hasProject: hasProject)
|
||||
context.coordinator.updateGitView(open: gitViewOpen)
|
||||
context.coordinator.guardClose()
|
||||
}
|
||||
|
||||
@@ -48,6 +50,7 @@ final class WindowCoordinator: NSObject {
|
||||
/// Set once the unsaved prompt said yes, so the second close goes through.
|
||||
private var closeApproved = false
|
||||
private var isAskingToClose = false
|
||||
private var gitViewOpen = false
|
||||
|
||||
init(model: WorkspaceModel) {
|
||||
self.model = model
|
||||
@@ -103,6 +106,14 @@ final class WindowCoordinator: NSObject {
|
||||
AppName.set(hasProject ? title : AppName.standard)
|
||||
}
|
||||
|
||||
/// Opening the Git view takes the keyboard from the column behind it at once; its message field
|
||||
/// takes focus a run loop later, so typing never lands in a covered terminal.
|
||||
func updateGitView(open: Bool) {
|
||||
defer { gitViewOpen = open }
|
||||
guard open, !gitViewOpen, let window else { return }
|
||||
window.makeFirstResponder(nil)
|
||||
}
|
||||
|
||||
private func configure(_ window: NSWindow) {
|
||||
window.title = model.title
|
||||
window.titleVisibility = .hidden
|
||||
@@ -203,19 +214,20 @@ final class WindowCoordinator: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// Source Control and Explorer have no text view to focus, so they hold the keyboard by clearing first responder.
|
||||
/// The Explorer has no text view to focus, so it holds the keyboard by clearing first responder.
|
||||
private func takeFocus(for panel: Panel, in window: NSWindow) {
|
||||
if panel == .sourceControl || panel == .explorer { window.makeFirstResponder(nil) }
|
||||
if panel == .explorer { window.makeFirstResponder(nil) }
|
||||
}
|
||||
|
||||
private func handleMouseDown(_ event: NSEvent) {
|
||||
guard let window, event.window === window, model.root != nil, !model.overlay.isPresented else { return }
|
||||
guard let window, event.window === window, model.root != nil, !model.overlay.isPresented,
|
||||
!model.layout.isGitViewOpen else { return }
|
||||
let point = event.locationInWindow
|
||||
let height = window.contentView?.bounds.height ?? window.frame.height
|
||||
guard height - point.y > Metrics.titleBar, point.y > Metrics.statusBar else { return }
|
||||
guard let panel = model.layout.panel(atX: point.x, splitterMargin: 4) else { return }
|
||||
model.pointerFocused(panel)
|
||||
guard panel == .sourceControl || panel == .explorer else { return }
|
||||
guard panel == .explorer else { return }
|
||||
// A row click pulls the keyboard out of a text view in another column; otherwise typing lands there.
|
||||
DispatchQueue.main.async { [weak self, weak window] in
|
||||
guard let self, let window, let view = window.firstResponder as? NSView,
|
||||
@@ -235,8 +247,9 @@ final class WindowCoordinator: NSObject {
|
||||
var hasSelection = false
|
||||
var editorSelection: TextSelectionInfo?
|
||||
var seed = ""
|
||||
let gitViewOpen = model.layout.isGitViewOpen
|
||||
if let text = responder as? NSTextView {
|
||||
let column = column(of: text)
|
||||
let column = gitViewOpen ? nil : column(of: text)
|
||||
owner = .text(in: column)
|
||||
let range = text.selectedRange()
|
||||
hasSelection = range.length > 0
|
||||
@@ -270,7 +283,9 @@ final class WindowCoordinator: NSObject {
|
||||
activePanel: model.layout.activePanel,
|
||||
focusZone: model.layout.focusZone,
|
||||
recentFileCount: editor?.history.count ?? 0,
|
||||
searchSeed: seed
|
||||
searchSeed: seed,
|
||||
gitViewOpen: gitViewOpen,
|
||||
inGitConsole: responder is GitConsoleFieldEditor
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user