From 492ca219d34e56b4d4145545a6ab3d1a818f3a0e Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 3 Dec 2024 12:09:44 -0800 Subject: [PATCH] Fix panic in autoclosing (#21482) Closes #14961 Release Notes: - Fixed a panic when backspacing at the start of a buffer with `always_treat_brackets_as_autoclosed` enabled. --- 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 1e47eb46a891b07f3847990e63b1db9514ea79c2..88919f9295f48c05ec5db18d7d0e8affa06a6fc2 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4098,8 +4098,10 @@ impl Editor { if buffer.contains_str_at(selection.start, &pair.end) { let pair_start_len = pair.start.len(); - if buffer.contains_str_at(selection.start - pair_start_len, &pair.start) - { + if buffer.contains_str_at( + selection.start.saturating_sub(pair_start_len), + &pair.start, + ) { selection.start -= pair_start_len; selection.end += pair.end.len();