From cd4a9f317822d10c7f2aaf268ec301c0a05c3320 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 12 Mar 2022 13:03:45 +0100 Subject: [PATCH] Fix bug in selection position maintenance while renaming symbol We were resolving the selection with the wrong buffer, which now causes a panic because we don't check the anchor's `buffer_id` anymore. --- crates/editor/src/editor.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0544355359..ba16522972 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4517,25 +4517,32 @@ impl Editor { self.remove_blocks([rename.block_id].into_iter().collect(), cx); self.clear_highlighted_ranges::(cx); - let editor = rename.editor.read(cx); - let snapshot = self.buffer.read(cx).snapshot(cx); - let selection = editor.newest_selection_with_snapshot::(&snapshot); + let selection_in_rename_editor = rename.editor.read(cx).newest_selection::(cx); // Update the selection to match the position of the selection inside // the rename editor. + let snapshot = self.buffer.read(cx).read(cx); let rename_range = rename.range.to_offset(&snapshot); let start = snapshot - .clip_offset(rename_range.start + selection.start, Bias::Left) + .clip_offset( + rename_range.start + selection_in_rename_editor.start, + Bias::Left, + ) .min(rename_range.end); let end = snapshot - .clip_offset(rename_range.start + selection.end, Bias::Left) + .clip_offset( + rename_range.start + selection_in_rename_editor.end, + Bias::Left, + ) .min(rename_range.end); + drop(snapshot); + self.update_selections( vec![Selection { id: self.newest_anchor_selection().id, start, end, - reversed: selection.reversed, + reversed: selection_in_rename_editor.reversed, goal: SelectionGoal::None, }], None,