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.
This commit is contained in:
Antonio Scandurra 2022-03-12 13:03:45 +01:00
parent 71aa5e5360
commit cd4a9f3178

View file

@ -4517,25 +4517,32 @@ impl Editor {
self.remove_blocks([rename.block_id].into_iter().collect(), cx); self.remove_blocks([rename.block_id].into_iter().collect(), cx);
self.clear_highlighted_ranges::<Rename>(cx); self.clear_highlighted_ranges::<Rename>(cx);
let editor = rename.editor.read(cx); let selection_in_rename_editor = rename.editor.read(cx).newest_selection::<usize>(cx);
let snapshot = self.buffer.read(cx).snapshot(cx);
let selection = editor.newest_selection_with_snapshot::<usize>(&snapshot);
// Update the selection to match the position of the selection inside // Update the selection to match the position of the selection inside
// the rename editor. // the rename editor.
let snapshot = self.buffer.read(cx).read(cx);
let rename_range = rename.range.to_offset(&snapshot); let rename_range = rename.range.to_offset(&snapshot);
let start = 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); .min(rename_range.end);
let end = snapshot 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); .min(rename_range.end);
drop(snapshot);
self.update_selections( self.update_selections(
vec![Selection { vec![Selection {
id: self.newest_anchor_selection().id, id: self.newest_anchor_selection().id,
start, start,
end, end,
reversed: selection.reversed, reversed: selection_in_rename_editor.reversed,
goal: SelectionGoal::None, goal: SelectionGoal::None,
}], }],
None, None,