1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
//! User intent accepted by the reducer and completion events returned by effects.
use crate::app::{CommitLoadMode, DocumentRevision, RequestId, SearchDirection, VisibleTreeEntry};
use crate::domain::{
ChangedFile, CommitMessage, CommitPage, CommitSummary, DiffDocument, FileDocument, LocalBranch,
ObjectId, RepoPath, SearchHit, SemanticNavigationKind, SourcePosition, TreeEntry,
WorktreeChange,
};
use crate::git::GitError;
use crate::lsp::LspError;
use vim_navigation::Motion as VimMotion;
/// How a Vim mark determines the destination column.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MarkJumpTarget {
/// Move to the first non-blank byte of the marked line.
Line,
/// Preserve the exact marked byte column.
Exact,
}
impl MarkJumpTarget {
pub(crate) const fn is_linewise(self) -> bool {
matches!(self, Self::Line)
}
}
/// Whether a completed mark jump is added to the shared jump history.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum JumpHistory {
/// Add the location left by the jump to history.
Record,
/// Move without changing jump history.
Preserve,
}
impl JumpHistory {
pub(crate) const fn records_jump(self) -> bool {
matches!(self, Self::Record)
}
}
/// A semantic input handled by [`crate::app::AppState`].
///
/// Key bindings map terminal-specific input to these values so state updates do
/// not depend on crossterm events or a particular key layout.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
/// Leave the application event loop.
Quit,
/// Switch to unstaged worktree changes.
ShowChanges,
/// Switch to the paged commit-history view.
ShowHistory,
/// Switch to the commit graph.
ShowGraph,
/// Switch to the working-tree code viewer.
ShowCode,
/// Open the local-branch switcher from any view or document overlay.
OpenBranches,
/// Move focus to the preceding pane or search input.
FocusLeft,
/// Move focus to the following pane or search results.
FocusRight,
/// Move the current selection or scroll position up.
MoveUp,
/// Move the current selection or scroll position down.
MoveDown,
/// Move to the first item or line.
MoveTop,
/// Move to the last item or line.
MoveBottom,
/// Scroll the active document up by half a page.
HalfPageUp,
/// Scroll the active document down by half a page.
HalfPageDown,
/// Scroll a diff horizontally to the left.
ScrollLeft,
/// Scroll a diff horizontally to the right.
ScrollRight,
/// Move the focused Code cursor left, or move to the preceding pane.
MoveCursorLeft,
/// Move the focused Code cursor right, or move to the following pane.
MoveCursorRight,
/// Apply a count-aware Vim normal-mode movement.
VimMotion(VimMotion),
/// Set a Vim mark at the active Code cursor.
SetVimMark(char),
/// Jump to a Vim mark, either at its exact column or first non-blank.
JumpToVimMark {
/// Mark name supplied after backtick or apostrophe.
mark: char,
/// Whether to select the marked line or the exact byte column.
target: MarkJumpTarget,
/// Whether the jump updates the shared jump list.
history: JumpHistory,
},
/// Open or close language-server hover information at the Code cursor.
ToggleLspHover,
/// Open the LSP document-symbol/context chooser for the active source file.
OpenSymbolContext,
/// Open the active diff or file as a complete source document.
OpenFullFile,
/// Toggle a complete file between changed-line annotations and plain new state.
ToggleFullFileMode,
/// Toggle soft wrapping in all diff and source viewers.
ToggleWrap,
/// Request one standard semantic target from the enabled language server.
GoToSemanticTarget(SemanticNavigationKind),
/// Return to the source location preceding the latest semantic jump.
GoBackFromSemanticTarget,
/// Revisit the semantic location most recently left by a backward jump.
GoForwardFromSemanticTarget,
/// Move backward through the shared Vim/LSP jump list.
JumpListBack(usize),
/// Move forward through the shared Vim/LSP jump list.
JumpListForward(usize),
/// Reload data owned by the current view.
Refresh,
/// Toggle History's message/diff preview, or open/close the message elsewhere.
ToggleMessage,
/// Toggle between history summary and commit-detail layouts.
ToggleDetails,
/// Toggle the middle history pane between changed files and the commit tree.
ToggleTree,
/// Open repository-wide file-name search.
OpenFileSearch,
/// Open repository-wide fixed-text content search.
OpenContentSearch,
/// Activate the selected item; open text documents interpret Enter as `+`.
Activate,
/// Begin in-document search in the requested direction.
StartSearch(SearchDirection),
/// Append one character to an active search prompt.
InsertSearch(char),
/// Delete the last character from an active search prompt.
/// An already empty in-document prompt is cancelled; repository search stays open.
DeleteSearch,
/// Accept an active search prompt or move into repository search results.
ConfirmSearch,
/// Cancel the active prompt without closing the surrounding document.
CancelSearch,
/// Select the next in-document search match.
NextMatch,
/// Select the previous in-document search match.
PreviousMatch,
/// Open or close the key help overlay.
ToggleHelp,
/// Close the topmost overlay or return one navigation level.
CloseOverlay,
/// Dismiss active Diff/Code search highlights, otherwise close/back (default Esc).
DismissSearchOrClose,
/// Advance timers used for pending key sequences and deferred work.
Tick,
}
/// The completion of an asynchronous [`crate::app::GitEffect`].
///
/// Every variant carries the originating [`RequestId`]. The reducer ignores a
/// completion that no longer matches current state, preventing slow work from
/// replacing a newer selection or query.
#[derive(Debug)]
pub enum Event {
/// Completed local branch enumeration.
BranchesLoaded {
/// Identifier allocated when the picker opened or refreshed.
request_id: RequestId,
/// Local branches or a recoverable boundary error.
result: Result<Vec<LocalBranch>, GitError>,
},
/// Completed an explicitly requested branch switch.
BranchSwitched {
/// Identifier allocated when the selected branch was activated.
request_id: RequestId,
/// Git's result; failures never trigger a forced retry.
result: Result<(), GitError>,
},
/// Completed an unstaged-worktree status request.
ChangesLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Parsed changes or the Git boundary error.
result: Result<Vec<WorktreeChange>, GitError>,
},
/// Completed one page of commit history.
CommitsLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Whether the page replaces or extends the current history.
mode: CommitLoadMode,
/// Requested page, used to detect the end of history.
page: CommitPage,
/// Parsed commit summaries or the Git boundary error.
result: Result<Vec<CommitSummary>, GitError>,
},
/// Completed the changed-file list for a selected commit.
FilesLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Commit that was selected when loading began.
commit: ObjectId,
/// Parsed changed files or the Git boundary error.
result: Result<Vec<ChangedFile>, GitError>,
},
/// Completed a worktree or commit diff request.
DiffLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Bounded diff document or the Git boundary error.
result: Result<DiffDocument, GitError>,
},
/// Completed a full commit-message request.
MessageLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Commit that was selected when loading began.
commit: ObjectId,
/// Complete message or the Git boundary error.
result: Result<CommitMessage, GitError>,
},
/// Completed one lazy commit-tree directory request.
TreeLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Commit whose tree is being expanded.
commit: ObjectId,
/// Visible directory receiving the children, or `None` for the root.
parent: Option<VisibleTreeEntry>,
/// Direct tree children or the Git boundary error.
result: Result<Vec<TreeEntry>, GitError>,
},
/// Completed the latest repository file or content search.
RepositorySearchLoaded {
/// Identifier allocated when the query changed.
request_id: RequestId,
/// Bounded search results or the Git boundary error.
result: Result<Vec<SearchHit>, GitError>,
},
/// Completed history loading for one repository path.
FileHistoryLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Path that was selected when loading began.
path: RepoPath,
/// Commit summaries touching the file or the Git boundary error.
result: Result<Vec<CommitSummary>, GitError>,
},
/// Completed a bounded current-file read.
FileContentLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Path that was selected when loading began.
path: RepoPath,
/// Typed file document or the filesystem/Git boundary error.
result: Result<FileDocument, GitError>,
},
/// Completed the working-tree file list used by the code viewer.
CodeTreeLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Repository-relative file paths or the Git boundary error.
result: Result<Vec<RepoPath>, GitError>,
},
/// Completed a bounded code-viewer file read.
CodeFileLoaded {
/// Identifier allocated when the request began.
request_id: RequestId,
/// Path that was selected when loading began.
path: RepoPath,
/// Typed file document or the filesystem/Git boundary error.
result: Result<FileDocument, GitError>,
},
/// Completed a full working-tree or historical source-file read.
FullFileLoaded {
/// Identifier used to reject an obsolete response.
request_id: RequestId,
/// Snapshot selected when loading began.
revision: crate::domain::FileRevision,
/// Repository path selected when loading began.
path: RepoPath,
/// Typed source document or Git/filesystem boundary error.
result: Result<FileDocument, GitError>,
},
/// Completed the latest document-symbol request.
DocumentSymbolsCompleted {
/// Identifier allocated for the symbol-list intent.
request_id: RequestId,
/// Document selected when the request was sent.
path: RepoPath,
/// Full-file document generation used to reject refresh races.
document_revision: DocumentRevision,
/// Flattened symbols using UTF-8 byte source positions.
result: Result<Vec<crate::domain::DocumentSymbol>, LspError>,
},
/// Completed the latest semantic navigation request.
SemanticNavigationCompleted {
/// Identifier allocated for the navigation intent.
request_id: RequestId,
/// Document selected when the request was sent.
path: RepoPath,
/// Cursor selected when the request was sent.
position: SourcePosition,
/// Code document generation selected when the request was sent.
document_revision: DocumentRevision,
/// Requested standard navigation operation.
kind: SemanticNavigationKind,
/// Normalized repository or explicitly unsupported targets.
result: Result<Vec<crate::domain::NavigationTarget>, LspError>,
},
/// Completed the latest language-server hover request.
LspHoverCompleted {
/// Identifier allocated for the hover intent.
request_id: RequestId,
/// Document selected when the request was sent.
path: RepoPath,
/// Cursor selected when the request was sent.
position: SourcePosition,
/// Code document generation selected when the request was sent.
document_revision: DocumentRevision,
/// Plain or Markdown-formatted hover text, when the server has any.
result: Result<Option<String>, LspError>,
},
/// Bounded status text from the server handling the current LSP request.
LspStatus {
/// LSP request for which the status is relevant.
request_id: RequestId,
/// Sanitized server progress or log text.
message: String,
},
}