chiark / gitweb /
Stop activity states loitering in initial_util.
authorSimon Tatham <anakin@pobox.com>
Thu, 25 Jan 2024 08:38:45 +0000 (08:38 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 25 Jan 2024 08:38:45 +0000 (08:38 +0000)
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.

src/activity_stack.rs
src/tui.rs

index 1f20a9d3a50d390dad79c06cd393663e8fc1cb48..eeac1e674f0a7cb635235ed342bd71c1c858b03d 100644 (file)
@@ -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) => {
index 74324dcbdd4aea298d5cbac0dd1c5b0567cd51b1..253caf463600451b4da060661fab2ad3a1ca8283 100644 (file)
@@ -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,