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
//! Action dispatch — revision lenses (plans/0016): refs, history, blame, and the preview submode's enter/exit
//! (moved from app/mod.rs, plans/0021 M1 — a pure move, zero behavior
//! change).
use super::super::App;
use super::super::provider_status;
use crate::action::Action;
use crate::components::refs_popup::RefsPopup;
use crate::mode::Mode;
impl App {
/// This domain's arms: `Some(action)` back when not ours, so the
/// next domain tries it; arm bodies are moved verbatim.
pub(crate) fn try_lenses(&mut self, action: Action) -> Option<Action> {
let _consumed: bool = match action {
Action::LeaderRefs => {
self.mode = Mode::Browse;
if !self.provider.capabilities().refs {
self.status = Some("provider has no revision listing".into());
} else if let Some((owner, name)) = self.browser.repo_coords() {
let current = self
.browser
.current_ref()
.or_else(|| self.browser.branch())
.unwrap_or("main")
.to_string();
self.refs_baseline = self.browser.current_ref().map(str::to_string);
self.refs_popup = Some(RefsPopup::new(¤t));
self.spawn_refs(format!("{owner}/{name}"));
} else {
self.status = Some("open a repo to switch revisions".into());
}
true
}
Action::RefsPreview(name) => {
// Live preview: the crumb follows the cursor (no fetch
// until commit).
self.browser.set_current_ref(Some(name));
true
}
Action::RefsCommit(name) => {
self.refs_popup = None;
self.refs_baseline = Some(name.clone());
self.browser.set_current_ref(Some(name.clone()));
self.status = Some(format!("switched to {name}"));
// The ref is read at spawn — refetch the tree now.
if let Some((owner, name)) = self.browser.repo_coords() {
self.handle_action(Action::LoadRepoTree { owner, name });
}
true
}
Action::LeaderPreview => {
self.mode = Mode::Browse;
if self.browser.repo_coords().is_none() {
self.status = Some("open a repo first".into());
} else {
self.mode = Mode::Preview;
}
true
}
Action::ExitPreview => {
// The commit-view ladder: Esc restores the present-day
// blob first, exits the submode second.
if self.browser.at_commit_view() {
self.browser.commit_view_close();
} else {
self.mode = Mode::Browse;
}
true
}
Action::BlameToggle => {
// 0019 parity: the search view's expanded pane runs the
// same lens at the hit's default branch.
if let Some(view) = &mut self.search_view {
if view.blame_active() {
view.blame_clear();
} else if !self.provider.capabilities().blame {
self.status = Some("provider has no blame".into());
} else if !view.blame_toggle_on() {
self.status = Some("blame: preview is not a text file".into());
} else if let Some((repo, path, branch)) = view.blame_needed() {
view.blame_mark_loading(path.clone());
let ref_ = if branch.is_empty() {
None
} else {
Some(branch)
};
self.spawn_blame(repo, path, ref_);
self.status = Some("blame…".into());
}
} else if self.browser.preview.blaming() {
self.browser.clear_blame();
} else if !self.provider.capabilities().blame {
// Honest absence (Bitbucket has no blame API).
self.status = Some("provider has no blame".into());
} else if !self.browser.blame_toggle_on() {
self.status = Some("blame: preview is not a text file".into());
} else if let Some(path) = self.browser.blame_needed_for()
&& let Some((owner, name)) = self.browser.repo_coords()
{
self.browser.blame_mark_loading(path.clone());
let ref_ = self.browser.current_ref().map(str::to_string);
self.spawn_blame(format!("{owner}/{name}"), path, ref_);
self.status = Some("blame…".into());
}
true
}
Action::PreviewEnter => {
// Blaming: Enter opens the line's commit in the history
// lens; otherwise Enter is the editor handoff.
match self.browser.blame_line_sha() {
Some(sha) if self.provider.capabilities().log => {
if self.browser.open_history(Some(sha)) {
self.open_history_fetch();
self.history_return = Some(Mode::Preview);
self.mode = Mode::History;
}
}
_ => self.handle_action(Action::OpenSelected),
}
true
}
Action::LeaderHistory => {
let back = self.mode;
self.mode = Mode::Browse;
if !self.provider.capabilities().log {
self.status = Some("provider has no commit log".into());
} else if self.browser.open_history(None) {
self.history_return = Some(if back == Mode::Preview {
Mode::Preview
} else {
Mode::Browse
});
self.open_history_fetch();
self.mode = Mode::History;
} else {
self.status = Some("preview a file for its history".into());
}
true
}
Action::HistoryFilterBegin => {
self.browser.history_begin_filter();
true
}
Action::HistoryYank => {
// The permalink that never rots: the URL carries the
// commit sha as its ref.
let target = self.browser.repo_coords().zip(self.browser.history_pick());
if let Some(((owner, name), (path, sha))) = target {
match self.provider.web_url(
&format!("{owner}/{name}"),
&path,
&sha,
None,
None,
true,
) {
Ok(u) => {
self.pending_clipboard = Some(u.clone());
self.status = Some(format!("yanked {u}"));
}
Err(e) => self.status = Some(provider_status(&e)),
}
}
true
}
Action::HistoryUp => {
self.browser.history_move(-1);
true
}
Action::HistoryDown => {
self.browser.history_move(1);
true
}
Action::HistoryOpen => {
// Open the file at the picked commit — bytes land via
// BlobAtLoaded; the restore point is noted there.
let target = self.browser.repo_coords().zip(self.browser.history_pick());
let entry = self.browser.history_pick_entry();
if let (Some(((owner, name), (path, sha))), Some(entry)) = (target, entry) {
self.spawn_blob_at(
format!("{owner}/{name}"),
path,
sha,
entry.subject,
entry.author,
entry.date,
);
self.status = Some("opening at commit".into());
}
true
}
Action::HistoryClose => {
// The wizard ladder: a committed filter clears first,
// the next Esc closes.
if self.browser.history_esc() {
self.mode = self.history_return.take().unwrap_or(Mode::Browse);
}
true
}
_ => return Some(action),
};
debug_assert!(_consumed);
None
}
}