Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 02/02: rewrite ThreadIndexMode#multi_kill to work like the other label methods
Date: Sun, 11 Oct 2026 08:23:34 +1100	[thread overview]
Message-ID: <20261010212332.B83AB296276@bl2.djc.id.au> (raw)
In-Reply-To: <179166741234.335316.11439183706167653222@bl2.djc.id.au>

New commit on branch develop:
https://supmua.dev/git/sup/commit/cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269.html

commit cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Oct 10 20:34:24 2026 +1100

    rewrite ThreadIndexMode#multi_kill to work like the other label methods
    
    Avoids race conditions which arise from invoking Index.save_thread
    before regen_text.
    
    Fixes #488.
---
 lib/sup/modes/thread_index_mode.rb | 55 +++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/lib/sup/modes/thread_index_mode.rb b/lib/sup/modes/thread_index_mode.rb
index 4172f3e0..4414d35d 100644
--- a/lib/sup/modes/thread_index_mode.rb
+++ b/lib/sup/modes/thread_index_mode.rb
@@ -494,6 +494,29 @@ EOS
     threads.each { |t| Index.save_thread t }
   end
 
+  ## returns an undo lambda
+  def actually_toggle_killed t
+    if t.has_label? :killed
+      t.remove_label :killed
+      add_or_unhide t.first
+      UpdateManager.relay self, :labeled, t.first
+      lambda do
+        t.apply_label :killed
+        hide_thread t
+        UpdateManager.relay self, :labeled, t.first
+      end
+    else
+      t.apply_label :killed
+      hide_thread t
+      UpdateManager.relay self, :labeled, t.first
+      lambda do
+        t.remove_label :killed
+        add_or_unhide t.first
+        UpdateManager.relay self, :labeled, t.first
+      end
+    end
+  end
+
   def kill
     t = cursor_thread or return
     multi_kill [t]
@@ -507,35 +530,13 @@ EOS
 
   ## m-m-m-m-MULTI-KILL
   def multi_kill threads
-    UndoManager.register "killing/unkilling #{threads.size.pluralize 'threads'}" do
-      threads.each do |t|
-        if t.toggle_label :killed
-          add_or_unhide t.first
-        else
-          hide_thread t
-        end
-      end.each do |t|
-        UpdateManager.relay self, :labeled, t.first
-        Index.save_thread t
-      end
-      regen_text
-    end
-
-    threads.each do |t|
-      if t.toggle_label :killed
-        hide_thread t
-      else
-        add_or_unhide t.first
-      end
-    end.each do |t|
-      # send 'labeled'... this might be more specific
-      UpdateManager.relay self, :labeled, t.first
-      Index.save_thread t
-    end
-
+    undos = threads.map { |t| actually_toggle_killed t }
+    UndoManager.register "killing/unkilling #{threads.size.pluralize 'threads'}", undos,
+                         lambda { regen_text }, lambda { threads.each { |t| Index.save_thread t } }
+    regen_text
+    threads.each { |t| Index.save_thread t }
     killed, unkilled = threads.partition { |t| t.has_label? :killed }.map(&:size)
     BufferManager.flash "#{killed.pluralize 'thread'} killed, #{unkilled} unkilled"
-    regen_text
   end
 
   def cleanup

      parent reply	other threads:[~2026-10-10 21:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10 21:23 [sup.git] branch develop updated (a17638d3 -> cf3a2e38) Dan Callaghan
2026-10-10 21:23 ` [sup.git] 01/02: fix ambiguous / warning in new emit_xterm_title method Dan Callaghan
2026-10-10 21:23 ` Dan Callaghan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261010212332.B83AB296276@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox