mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 10:29:35 +03:00
Introduce a struct for spanned_rows result
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
029460bf7e
commit
a6a8f4fd81
@ -855,7 +855,7 @@ impl Editor {
|
|||||||
|
|
||||||
let mut selections = self.selections(app).iter().peekable();
|
let mut selections = self.selections(app).iter().peekable();
|
||||||
while let Some(selection) = selections.next() {
|
while let Some(selection) = selections.next() {
|
||||||
let (mut rows, _) = selection.spanned_rows(false, &display_map);
|
let mut rows = selection.spanned_rows(false, &display_map).buffer_rows;
|
||||||
let goal_display_column = selection
|
let goal_display_column = selection
|
||||||
.head()
|
.head()
|
||||||
.to_display_point(&display_map, Bias::Left)
|
.to_display_point(&display_map, Bias::Left)
|
||||||
@ -863,7 +863,7 @@ impl Editor {
|
|||||||
|
|
||||||
// Accumulate contiguous regions of rows that we want to delete.
|
// Accumulate contiguous regions of rows that we want to delete.
|
||||||
while let Some(next_selection) = selections.peek() {
|
while let Some(next_selection) = selections.peek() {
|
||||||
let (next_rows, _) = next_selection.spanned_rows(false, &display_map);
|
let next_rows = next_selection.spanned_rows(false, &display_map).buffer_rows;
|
||||||
if next_rows.start <= rows.end {
|
if next_rows.start <= rows.end {
|
||||||
rows.end = next_rows.end;
|
rows.end = next_rows.end;
|
||||||
selections.next().unwrap();
|
selections.next().unwrap();
|
||||||
@ -942,9 +942,9 @@ impl Editor {
|
|||||||
let mut selections_iter = selections.iter_mut().peekable();
|
let mut selections_iter = selections.iter_mut().peekable();
|
||||||
while let Some(selection) = selections_iter.next() {
|
while let Some(selection) = selections_iter.next() {
|
||||||
// Avoid duplicating the same lines twice.
|
// Avoid duplicating the same lines twice.
|
||||||
let (mut rows, _) = selection.spanned_rows(false, &display_map);
|
let mut rows = selection.spanned_rows(false, &display_map).buffer_rows;
|
||||||
while let Some(next_selection) = selections_iter.peek() {
|
while let Some(next_selection) = selections_iter.peek() {
|
||||||
let (next_rows, _) = next_selection.spanned_rows(false, &display_map);
|
let next_rows = next_selection.spanned_rows(false, &display_map).buffer_rows;
|
||||||
if next_rows.start <= rows.end - 1 {
|
if next_rows.start <= rows.end - 1 {
|
||||||
rows.end = next_rows.end;
|
rows.end = next_rows.end;
|
||||||
selections_iter.next().unwrap();
|
selections_iter.next().unwrap();
|
||||||
@ -997,10 +997,16 @@ impl Editor {
|
|||||||
while let Some(selection) = selections.next() {
|
while let Some(selection) = selections.next() {
|
||||||
// Accumulate contiguous regions of rows that we want to move.
|
// Accumulate contiguous regions of rows that we want to move.
|
||||||
contiguous_selections.push(selection.point_range(buffer));
|
contiguous_selections.push(selection.point_range(buffer));
|
||||||
let (mut buffer_rows, mut display_rows) = selection.spanned_rows(false, &display_map);
|
let SpannedRows {
|
||||||
|
mut buffer_rows,
|
||||||
|
mut display_rows,
|
||||||
|
} = selection.spanned_rows(false, &display_map);
|
||||||
|
|
||||||
while let Some(next_selection) = selections.peek() {
|
while let Some(next_selection) = selections.peek() {
|
||||||
let (next_buffer_rows, next_display_rows) =
|
let SpannedRows {
|
||||||
next_selection.spanned_rows(false, &display_map);
|
buffer_rows: next_buffer_rows,
|
||||||
|
display_rows: next_display_rows,
|
||||||
|
} = next_selection.spanned_rows(false, &display_map);
|
||||||
if next_buffer_rows.start <= buffer_rows.end {
|
if next_buffer_rows.start <= buffer_rows.end {
|
||||||
buffer_rows.end = next_buffer_rows.end;
|
buffer_rows.end = next_buffer_rows.end;
|
||||||
display_rows.end = next_display_rows.end;
|
display_rows.end = next_display_rows.end;
|
||||||
@ -1014,8 +1020,11 @@ impl Editor {
|
|||||||
// Cut the text from the selected rows and paste it at the start of the previous line.
|
// Cut the text from the selected rows and paste it at the start of the previous line.
|
||||||
if display_rows.start != 0 {
|
if display_rows.start != 0 {
|
||||||
let start = Point::new(buffer_rows.start, 0).to_offset(buffer);
|
let start = Point::new(buffer_rows.start, 0).to_offset(buffer);
|
||||||
let end = Point::new(buffer_rows.end - 1, buffer.line_len(buffer_rows.end - 1))
|
let end = Point::new(
|
||||||
.to_offset(buffer);
|
buffer_rows.end - 1,
|
||||||
|
buffer.line_len(buffer_rows.end - 1),
|
||||||
|
)
|
||||||
|
.to_offset(buffer);
|
||||||
|
|
||||||
let prev_row_display_start = DisplayPoint::new(display_rows.start - 1, 0);
|
let prev_row_display_start = DisplayPoint::new(display_rows.start - 1, 0);
|
||||||
let prev_row_buffer_start = display_map.prev_row_boundary(prev_row_display_start).1;
|
let prev_row_buffer_start = display_map.prev_row_boundary(prev_row_display_start).1;
|
||||||
@ -1081,10 +1090,15 @@ impl Editor {
|
|||||||
while let Some(selection) = selections.next() {
|
while let Some(selection) = selections.next() {
|
||||||
// Accumulate contiguous regions of rows that we want to move.
|
// Accumulate contiguous regions of rows that we want to move.
|
||||||
contiguous_selections.push(selection.point_range(buffer));
|
contiguous_selections.push(selection.point_range(buffer));
|
||||||
let (mut buffer_rows, mut display_rows) = selection.spanned_rows(false, &display_map);
|
let SpannedRows {
|
||||||
|
mut buffer_rows,
|
||||||
|
mut display_rows,
|
||||||
|
} = selection.spanned_rows(false, &display_map);
|
||||||
while let Some(next_selection) = selections.peek() {
|
while let Some(next_selection) = selections.peek() {
|
||||||
let (next_buffer_rows, next_display_rows) =
|
let SpannedRows {
|
||||||
next_selection.spanned_rows(false, &display_map);
|
buffer_rows: next_buffer_rows,
|
||||||
|
display_rows: next_display_rows,
|
||||||
|
} = next_selection.spanned_rows(false, &display_map);
|
||||||
if next_buffer_rows.start <= buffer_rows.end {
|
if next_buffer_rows.start <= buffer_rows.end {
|
||||||
buffer_rows.end = next_buffer_rows.end;
|
buffer_rows.end = next_buffer_rows.end;
|
||||||
display_rows.end = next_display_rows.end;
|
display_rows.end = next_display_rows.end;
|
||||||
@ -1668,7 +1682,7 @@ impl Editor {
|
|||||||
let mut selections = self.selections(cx).to_vec();
|
let mut selections = self.selections(cx).to_vec();
|
||||||
let max_point = buffer.max_point();
|
let max_point = buffer.max_point();
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let (rows, _) = selection.spanned_rows(true, &display_map);
|
let rows = selection.spanned_rows(true, &display_map).buffer_rows;
|
||||||
selection.start = buffer.anchor_before(Point::new(rows.start, 0));
|
selection.start = buffer.anchor_before(Point::new(rows.start, 0));
|
||||||
selection.end = buffer.anchor_before(cmp::min(max_point, Point::new(rows.end, 0)));
|
selection.end = buffer.anchor_before(cmp::min(max_point, Point::new(rows.end, 0)));
|
||||||
selection.reversed = false;
|
selection.reversed = false;
|
||||||
|
@ -17,6 +17,11 @@ pub enum SelectionGoal {
|
|||||||
ColumnRange { start: u32, end: u32 },
|
ColumnRange { start: u32, end: u32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct SpannedRows {
|
||||||
|
pub buffer_rows: Range<u32>,
|
||||||
|
pub display_rows: Range<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Selection {
|
pub struct Selection {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
@ -93,7 +98,7 @@ impl Selection {
|
|||||||
&self,
|
&self,
|
||||||
include_end_if_at_line_start: bool,
|
include_end_if_at_line_start: bool,
|
||||||
map: &DisplayMapSnapshot,
|
map: &DisplayMapSnapshot,
|
||||||
) -> (Range<u32>, Range<u32>) {
|
) -> SpannedRows {
|
||||||
let display_start = self.start.to_display_point(map, Bias::Left);
|
let display_start = self.start.to_display_point(map, Bias::Left);
|
||||||
let mut display_end = self.end.to_display_point(map, Bias::Right);
|
let mut display_end = self.end.to_display_point(map, Bias::Right);
|
||||||
if !include_end_if_at_line_start
|
if !include_end_if_at_line_start
|
||||||
@ -107,9 +112,9 @@ impl Selection {
|
|||||||
let (display_start, buffer_start) = map.prev_row_boundary(display_start);
|
let (display_start, buffer_start) = map.prev_row_boundary(display_start);
|
||||||
let (display_end, buffer_end) = map.next_row_boundary(display_end);
|
let (display_end, buffer_end) = map.next_row_boundary(display_end);
|
||||||
|
|
||||||
(
|
SpannedRows {
|
||||||
buffer_start.row..buffer_end.row + 1,
|
buffer_rows: buffer_start.row..buffer_end.row + 1,
|
||||||
display_start.row()..display_end.row() + 1,
|
display_rows: display_start.row()..display_end.row() + 1,
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user