From 0203de046d2c0fc15c851b42fa9c8a762a82d71a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 26 Jan 2022 10:15:31 +0000 Subject: [PATCH] Don't repeatedly try to merge blocks in the select boundary UI. An optimization to workaround new sanity checks introduced for #841 --- ltn/src/select_boundary.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ltn/src/select_boundary.rs b/ltn/src/select_boundary.rs index 68444c4769..ad5307dfac 100644 --- a/ltn/src/select_boundary.rs +++ b/ltn/src/select_boundary.rs @@ -22,6 +22,10 @@ pub struct SelectBoundary { frontier: BTreeSet, orig_partitioning: Partitioning, + + // As an optimization, don't repeatedly attempt to make an edit that'll fail. The bool is + // whether the block is already included or not + last_failed_change: Option<(BlockID, bool)>, } impl SelectBoundary { @@ -34,6 +38,7 @@ impl SelectBoundary { frontier: BTreeSet::new(), orig_partitioning: app.session.partitioning.clone(), + last_failed_change: None, }; let initial_boundary = app.session.partitioning.neighborhood_block(id); @@ -102,6 +107,11 @@ impl SelectBoundary { // If the block is part of the current neighborhood, remove it. Otherwise add it. It's assumed // this block is in the previous frontier fn toggle_block(&mut self, ctx: &mut EventCtx, app: &mut App, id: BlockID) -> Transition { + if self.last_failed_change == Some((id, self.currently_have_block(app, id))) { + return Transition::Keep; + } + self.last_failed_change = None; + match self.try_toggle_block(app, id) { Ok(Some(new_neighborhood)) => { app.session.partitioning.recalculate_coloring(); @@ -140,6 +150,7 @@ impl SelectBoundary { self.panel = make_panel(ctx, app); } Err(err) => { + self.last_failed_change = Some((id, self.currently_have_block(app, id))); let label = err.to_string().text_widget(ctx); self.panel.replace(ctx, "warning", label); }