From c6466c1cce540e1ec4b7234bc293d2bebb106529 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 18 Oct 2023 11:34:35 -0700 Subject: [PATCH] Fix possibility of infinite loop in selections_with_autoclose_regions (#3138) Previously, that method could loop forever if the editor's autoclose regions had unexpected selection ids. Something must have changed recently that allowed this invariant to be violated, but regardless, this code should not have relied on that invariant to terminate like this. --- crates/editor/src/editor.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7aca4ab98f..d755723085 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3286,8 +3286,10 @@ impl Editor { i = 0; } else if pair_state.range.start.to_offset(buffer) > range.end { break; - } else if pair_state.selection_id == selection.id { - enclosing = Some(pair_state); + } else { + if pair_state.selection_id == selection.id { + enclosing = Some(pair_state); + } i += 1; } }