From 99b776b59394f4d38b872946dc5c619f1f50b959 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 24ffa64a6af73aef827cea17757e5c0e6a4e94c2..439dd6c323b9dc727e2c2bd462358c379fc427ea 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2877,8 +2877,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; } }