From: Simon Tatham Date: Thu, 25 Jan 2024 08:38:45 +0000 (+0000) Subject: Stop activity states loitering in initial_util. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=ddd114efdb6e07054fac12a2823ae828831c5ecd;p=mastodonochrome.git Stop activity states loitering in initial_util. In order to respond to Alt+E by putting a prompt at the bottom of the current activity (rather than the naïve approach of breaking the keypress into ESC + E, switching to the utilities menu in response to the ESC, and then putting the prompt at the bottom of that much less helpful screen), we remember an activity from the start of the overall keypress, in the 'initial_util' field of ActivityStack. But then we _leave_ it there, and don't clean it up - which means it's returned by ActivityStack::iter(), and hence inhibits garbage collection of the associated activity state. So a thing could linger in there for ages despite not actually being on the stack. --- diff --git a/src/activity_stack.rs b/src/activity_stack.rs index 1f20a9d..eeac1e6 100644 --- a/src/activity_stack.rs +++ b/src/activity_stack.rs @@ -138,6 +138,11 @@ impl ActivityStack { self.initial_util = self.util.clone(); } + pub fn completed_event(&mut self) { + // At the end of an event, clear initial_util again. + self.initial_util = None; + } + pub fn goto(&mut self, act: Activity) { match act { Activity::Util(x) => { diff --git a/src/tui.rs b/src/tui.rs index 74324dc..253caf4 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -561,6 +561,8 @@ impl Tui { PhysicalAction::Nothing => (), } } + + self.state.completed_event(); } } @@ -739,6 +741,11 @@ impl TuiLogicalState { self.activity_stack.new_event(); } + fn completed_event(&mut self) { + self.activity_stack.completed_event(); + self.gc_activity_states(); + } + fn handle_keypress( &mut self, key: OurKey,