adds nice git interface
This commit is contained in:
@@ -69,36 +69,47 @@ extension WorkspaceModel {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Git view
|
||||
|
||||
/// Opens the Git view on its message field, re-reads git and fetches origin; an open view only takes the field again.
|
||||
func openGitView() {
|
||||
if !layout.isGitViewOpen {
|
||||
layout.openGitView()
|
||||
scheduleRefresh(.git)
|
||||
if let sourceControl { track { await sourceControl.viewOpened() } }
|
||||
}
|
||||
focusRequest = FocusRequest(.commitMessage)
|
||||
}
|
||||
|
||||
/// Hands the keyboard back to the column that had it before the view opened.
|
||||
func closeGitView() {
|
||||
guard layout.isGitViewOpen else { return }
|
||||
layout.closeGitView()
|
||||
guard let panel = layout.activePanel else {
|
||||
focusRequest = nil
|
||||
return
|
||||
}
|
||||
focusRequest = FocusRequest(.panel(panel))
|
||||
if panel == .editor { editor?.requestTextFocus() }
|
||||
}
|
||||
|
||||
// MARK: Focus and the row cursor
|
||||
|
||||
func focus(_ panel: Panel) {
|
||||
let previous = layout.activePanel
|
||||
layout.focus(panel)
|
||||
guard layout.activePanel == panel else { return }
|
||||
focusRequest = FocusRequest(.panel(panel))
|
||||
if panel == .editor { editor?.requestTextFocus() }
|
||||
if panel == .sourceControl && previous != .sourceControl { scheduleRefresh(.git) }
|
||||
}
|
||||
|
||||
func moveRowCursor(by step: Int) {
|
||||
switch layout.activePanel {
|
||||
case .sourceControl: sourceControl?.moveSelection(by: step)
|
||||
case .explorer: explorer?.moveSelection(by: step, showHidden: layout.showHidden)
|
||||
default: break
|
||||
}
|
||||
guard layout.activePanel == .explorer else { return }
|
||||
explorer?.moveSelection(by: step, showHidden: layout.showHidden)
|
||||
}
|
||||
|
||||
func openSelectedRow() {
|
||||
switch layout.activePanel {
|
||||
case .sourceControl:
|
||||
guard let row = selectedGitRow() else { return }
|
||||
open(row.change.path, OpenOptions(side: row.change.staged ? .staged : .unstaged))
|
||||
case .explorer:
|
||||
guard let explorer, let row = selectedTreeRow() else { return }
|
||||
if row.row.kind == .directory { explorer.toggle(row.row.path) } else { open(row.row.path) }
|
||||
default:
|
||||
break
|
||||
}
|
||||
guard layout.activePanel == .explorer, let explorer, let row = selectedTreeRow() else { return }
|
||||
if row.row.kind == .directory { explorer.toggle(row.row.path) } else { open(row.row.path) }
|
||||
}
|
||||
|
||||
// MARK: Editor
|
||||
|
||||
Reference in New Issue
Block a user