tui: /diff drops accepted files from the edits log on close/send
This commit is contained in:
1 parent
95f1343ec1
commit
b73aeb9ae4
2 files changed
+28
-1
No files matched your search
@@ -1004,6 +1004,17 @@ fn show(app: &mut App, title: &str, text: String) {
|
||||
}
|
||||
|
||||
/// Returns a line to submit, if any.
|
||||
/// Accepted files leave the edits log, so the next `/diff` lists only what is still open.
|
||||
fn drop_accepted(app: &App) {
|
||||
let Some(r) = &app.review else { return };
|
||||
let acc = r.accepted();
|
||||
app.state
|
||||
.edits
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.retain(|e| !acc.contains(&e.path));
|
||||
}
|
||||
|
||||
fn on_key(app: &mut App, k: KeyEvent, abort: &AbortHandle) -> Option<String> {
|
||||
let ctrl = k.modifiers.contains(KeyModifiers::CONTROL);
|
||||
let alt = k.modifiers.contains(KeyModifiers::ALT);
|
||||
@@ -1051,7 +1062,10 @@ fn on_key(app: &mut App, k: KeyEvent, abort: &AbortHandle) -> Option<String> {
|
||||
}
|
||||
if let Some(r) = &mut app.review {
|
||||
match r.key(k) {
|
||||
review::Act::Close => app.review = None,
|
||||
review::Act::Close => {
|
||||
drop_accepted(app);
|
||||
app.review = None;
|
||||
}
|
||||
review::Act::Reverted(p) => {
|
||||
app.state
|
||||
.edits
|
||||
@@ -1062,6 +1076,7 @@ fn on_key(app: &mut App, k: KeyEvent, abort: &AbortHandle) -> Option<String> {
|
||||
}
|
||||
review::Act::Error(e) => app.t.push(Item::Error(e)),
|
||||
review::Act::Send(text) => {
|
||||
drop_accepted(app);
|
||||
app.review = None;
|
||||
return Some(text);
|
||||
}
|
||||
|
||||
@@ -283,6 +283,16 @@ impl Review {
|
||||
s
|
||||
}
|
||||
|
||||
/// Paths marked accepted; the app drops them from the edits log when the review ends.
|
||||
pub fn accepted(&self) -> Vec<PathBuf> {
|
||||
let ok = |f: &&File| f.state == State::Accepted;
|
||||
self.files
|
||||
.iter()
|
||||
.filter(ok)
|
||||
.map(|f| f.path.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn key(&mut self, k: KeyEvent) -> Act {
|
||||
if let Some(buf) = &mut self.input {
|
||||
match k.code {
|
||||
@@ -650,6 +660,8 @@ mod tests {
|
||||
r2.key(key('w'));
|
||||
let w = txt(r2.row_lines(&r2.files[0].rows[1], 40, false));
|
||||
assert!(w.len() > 2 && w[1].contains('↪'), "{w:?}");
|
||||
r.key(key('a'));
|
||||
assert_eq!(r.accepted(), vec![PathBuf::from("/x/a.rs")]);
|
||||
r.key(key('v'));
|
||||
assert!(!r.shown(&r.files[0].rows[2]));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user