adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
+54 -7
View File
@@ -9,6 +9,7 @@ import Testing
@Test(arguments: [
("p", Command.push), ("s", .save), ("m", .cycleMode), ("g", .toggleGit),
("l", .toggleAutoFit), (".", .toggleHidden), ("w", .closeFileOrWindow),
("1", .togglePane(.explorer)), ("2", .togglePane(.editor)), ("3", .togglePane(.terminal)),
])
func commandLettersMapToTheirCommand(key: String, command: Command) {
#expect(route(cmd(key)) == .perform(command))
@@ -41,9 +42,16 @@ import Testing
#expect(route(cmd("c"), KeyContext(owner: .terminal, hasTextSelection: true)) == .pass)
}
@Test func commandEnterCommitsExceptInTheCommitBoxItself() {
#expect(route(KeyPress(.enter, command: true)) == .perform(.commit))
#expect(route(KeyPress(.enter, command: true), KeyContext(owner: .text(in: .sourceControl))) == .pass)
@Test func commandEnterCommitsOnlyOverTheGitView() {
#expect(route(KeyPress(.enter, command: true)) == .pass)
#expect(route(KeyPress(.enter, command: true), KeyContext(owner: .text(in: .editor))) == .pass)
#expect(route(KeyPress(.enter, command: true), KeyContext(gitViewOpen: true)) == .perform(.commit))
}
@Test func commandEnterInTheGitConsoleStaysWithTheConsole() {
let console = KeyContext(owner: .text(in: nil), gitViewOpen: true, inGitConsole: true)
#expect(route(KeyPress(.enter, command: true), console) == .pass)
#expect(route(cmd("p"), console) == .perform(.push))
}
@Test func arrowsMoveTheRowCursorOnlyInAListWithoutAField() {
@@ -52,12 +60,12 @@ import Testing
#expect(route(KeyPress(.up), list) == .perform(.moveRowCursor(-1)))
#expect(route(KeyPress(.enter), list) == .perform(.openSelectedRow))
#expect(route(KeyPress(.down), KeyContext(activePanel: .editor)) == .pass)
#expect(route(KeyPress(.down), KeyContext(owner: .text(in: .sourceControl), activePanel: .sourceControl)) == .pass)
#expect(route(KeyPress(.down), KeyContext(owner: .text(in: .explorer), activePanel: .explorer)) == .pass)
#expect(route(KeyPress(.enter), KeyContext(owner: .terminal, activePanel: .terminal)) == .pass)
}
@Test func commandRightOpensTheRowMenuPassesASelectionOrMovesFocus() {
#expect(route(KeyPress(.right, command: true), KeyContext(activePanel: .sourceControl)) == .perform(.openRowMenu))
#expect(route(KeyPress(.right, command: true), KeyContext(activePanel: .explorer)) == .perform(.openRowMenu))
let selection = TextSelectionInfo(text: "x", startLine: 3, endLine: 4)
#expect(route(KeyPress(.right, command: true), KeyContext(owner: .text(in: .editor), editorTextSelection: selection))
== .perform(.passSelection(selection)))
@@ -83,7 +91,7 @@ import Testing
@Test func questionMarkOpensHelpButTypesInAField() {
#expect(route(KeyPress(.character("?"), shift: true)) == .perform(.showShortcuts))
#expect(route(KeyPress(.character("?"), shift: true), KeyContext(owner: .text(in: .sourceControl))) == .pass)
#expect(route(KeyPress(.character("?"), shift: true), KeyContext(owner: .text(in: .editor))) == .pass)
#expect(route(KeyPress(.character("?"), shift: true), KeyContext(owner: .terminal)) == .pass)
}
@@ -93,6 +101,45 @@ import Testing
#expect(route(KeyPress(.escape), KeyContext(owner: .terminal)) == .pass)
}
@Test func commandGTogglesTheGitViewFromAnywhere() {
#expect(route(cmd("g")) == .perform(.toggleGit))
#expect(route(cmd("g"), KeyContext(owner: .terminal)) == .perform(.toggleGit))
#expect(route(cmd("g"), KeyContext(owner: .text(in: nil), gitViewOpen: true)) == .perform(.toggleGit))
}
@Test func escapeClosesTheGitViewOnlyWhenNoOverlayIsOpen() {
let git = KeyContext(gitViewOpen: true)
#expect(route(KeyPress(.escape), git) == .perform(.closeGitView))
#expect(route(KeyPress(.escape), KeyContext(owner: .text(in: nil), gitViewOpen: true)) == .perform(.closeGitView))
#expect(route(KeyPress(.escape), KeyContext(overlay: .other, gitViewOpen: true)) == .perform(.dismissOverlay))
#expect(route(KeyPress(.escape), KeyContext(overlay: .diff(busy: false), gitViewOpen: true)) == .perform(.dismissOverlay))
#expect(route(KeyPress(.escape), KeyContext(overlay: .diff(busy: true), gitViewOpen: true)) == .pass)
#expect(route(KeyPress(.escape)) == .pass)
}
@Test func overTheGitViewCommitPushAndSearchWorkFromItsFields() {
let field = KeyContext(owner: .text(in: nil), gitViewOpen: true)
#expect(route(KeyPress(.enter, command: true), field) == .perform(.commit))
#expect(route(cmd("p"), field) == .perform(.push))
#expect(route(cmd("f"), field) == .perform(.showSearch(seed: "")))
#expect(route(cmd("g"), field) == .perform(.toggleGit))
#expect(route(cmd("2"), field) == .perform(.togglePane(.editor)))
}
@Test func overTheGitViewTheColumnKeysRestAndTypingReachesTheField() {
let git = KeyContext(activePanel: .explorer, focusZone: .editor, recentFileCount: 3, gitViewOpen: true)
#expect(route(KeyPress(.down), git) == .pass)
#expect(route(KeyPress(.enter), git) == .pass)
#expect(route(KeyPress(.right, command: true), git) == .pass)
#expect(route(KeyPress(.left, command: true), git) == .pass)
#expect(route(KeyPress(.down, command: true), git) == .pass)
#expect(route(cmd("a"), git) == .pass)
let field = KeyContext(owner: .text(in: nil), gitViewOpen: true)
#expect(route(KeyPress(.character("x")), field) == .pass)
#expect(route(KeyPress(.character("?"), shift: true), field) == .pass)
#expect(route(cmd("c"), KeyContext(owner: .text(in: nil), hasTextSelection: true, gitViewOpen: true)) == .pass)
}
@Test func anOpenOverlayOwnsEveryOtherKey() {
let search = KeyContext(overlay: .other, activePanel: .explorer)
#expect(route(cmd("g"), search) == .pass)
@@ -125,7 +172,7 @@ import Testing
#expect(route(cmd("p"), diff) == .perform(.push))
#expect(route(cmd("s"), diff) == .perform(.save))
#expect(route(cmd("c"), diff) == .perform(.focusCommitMessage))
#expect(route(KeyPress(.enter, command: true), diff) == .perform(.commit))
#expect(route(KeyPress(.enter, command: true), diff) == .pass)
#expect(route(KeyPress(.down, command: true), KeyContext(overlay: .diff(busy: false), focusZone: .editor, recentFileCount: 2))
== .perform(.showRecentFiles(initialSelection: 1)))
#expect(route(KeyPress(.escape), diff) == .perform(.dismissOverlay))