Fix editor::SplitSelectionIntoLines adding an extra line at the end (#25053)

Closes #4795

Release Notes:

- Fixed `editor::SplitSelectionIntoLines` adding an extra line at end
of selection
This commit is contained in:
João Marcos 2025-02-18 00:23:48 -03:00 committed by GitHub
parent 12aa270b9a
commit a8de6af641
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 100 additions and 26 deletions

View file

@ -9122,21 +9122,32 @@ impl Editor {
window: &mut Window,
cx: &mut Context<Self>,
) {
let mut to_unfold = Vec::new();
let selections = self
.selections
.all::<Point>(cx)
.into_iter()
.map(|selection| selection.start..selection.end)
.collect::<Vec<_>>();
self.unfold_ranges(&selections, true, true, cx);
let mut new_selection_ranges = Vec::new();
{
let selections = self.selections.all::<Point>(cx);
let buffer = self.buffer.read(cx).read(cx);
for selection in selections {
for row in selection.start.row..selection.end.row {
let cursor = Point::new(row, buffer.line_len(MultiBufferRow(row)));
new_selection_ranges.push(cursor..cursor);
}
new_selection_ranges.push(selection.end..selection.end);
to_unfold.push(selection.start..selection.end);
let is_multiline_selection = selection.start.row != selection.end.row;
// Don't insert last one if it's a multi-line selection ending at the start of a line,
// so this action feels more ergonomic when paired with other selection operations
let should_skip_last = is_multiline_selection && selection.end.column == 0;
if !should_skip_last {
new_selection_ranges.push(selection.end..selection.end);
}
}
}
self.unfold_ranges(&to_unfold, true, true, cx);
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.select_ranges(new_selection_ranges);
});