From b73aeb9ae43c996294e273e0754ab570af0a9d5e Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 14 Oct 2026 20:12:13 +0000 Subject: [PATCH] tui: /diff drops accepted files from the edits log on close/send --- crates/hx-tui/src/lib.rs | 17 ++++++++++++++++- crates/hx-tui/src/review.rs | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index 3269301..aaf5266 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -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 { 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 { } 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 { } review::Act::Error(e) => app.t.push(Item::Error(e)), review::Act::Send(text) => { + drop_accepted(app); app.review = None; return Some(text); } diff --git a/crates/hx-tui/src/review.rs b/crates/hx-tui/src/review.rs index aaebb8a..8a6c314 100644 --- a/crates/hx-tui/src/review.rs +++ b/crates/hx-tui/src/review.rs @@ -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 { + 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])); }