From 7a0f0394142f31cdd3e48dc0a7eb6e752fd4cd14 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 23:21:02 -0600 Subject: [PATCH] Fix panic in rename selections (cherry-pick #11033) (#11034) Cherry-picked Fix panic in rename selections (#11033) cc @someonetoignore Release Notes: - Fixed a panic when renaming with a selection (preview only) Co-authored-by: Conrad Irwin --- crates/editor/src/editor.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a2fc4d67cfbc0ff967367038154ffa03f4bc46c7..b6764eeca23d887be2abe8a4f6038f6f72d64e58 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8200,9 +8200,13 @@ impl Editor { cursor_offset_in_rename_range_end..cursor_offset_in_rename_range } }; - editor.change_selections(Some(Autoscroll::fit()), cx, |s| { - s.select_ranges([rename_selection_range]); - }); + if rename_selection_range.end > old_name.len() { + editor.select_all(&SelectAll, cx); + } else { + editor.change_selections(Some(Autoscroll::fit()), cx, |s| { + s.select_ranges([rename_selection_range]); + }); + } editor });