From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id B83AB296276; Sun, 11 Oct 2026 08:23:32 +1100 (AEDT) Date: Sun, 11 Oct 2026 08:23:34 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 02/02: rewrite ThreadIndexMode#multi_kill to work like the other label methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179166741234.335316.11439183706167653222@bl2.djc.id.au> References: <179166741234.335316.11439183706167653222@bl2.djc.id.au> Thread-Index: AQAAEjRW5kEjIkVGRXCXtbzIVo4KFQ== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup.git X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261010212332.B83AB296276@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269.html commit cf3a2e38fcc81e0515ea0557c6f837fd3cfdb269 Author: Dan Callaghan 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