Fix possibility of infinite loop in selections_with_autoclose_regions

Max Brunsfeld and Piotr created

Previously, that method could loop forever if the editor's autoclose
regions had unexpected selection ids.

Co-authored-by: Piotr <piotr@zed.dev>

Change summary

crates/editor/src/editor.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

Detailed changes

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;
                 }
             }