Unify visual line_mode and non line_mode operators

This commit is contained in:
Keith Simmons
2022-05-26 17:02:05 -07:00
parent 11569a869a
commit e93c49f4f0
12 changed files with 141 additions and 178 deletions
+12 -7
View File
@@ -279,16 +279,21 @@ impl DisplaySnapshot {
}
}
pub fn expand_to_line(&self, mut range: Range<Point>) -> Range<Point> {
(range.start, _) = self.prev_line_boundary(range.start);
(range.end, _) = self.next_line_boundary(range.end);
pub fn expand_to_line(&self, range: Range<Point>) -> Range<Point> {
let mut new_start = self.prev_line_boundary(range.start).0;
let mut new_end = self.next_line_boundary(range.end).0;
if range.is_empty() && range.start.row > 0 {
range.start.row -= 1;
range.start.column = self.buffer_snapshot.line_len(range.start.row);
if new_start.row == range.start.row && new_end.row == range.end.row {
if new_end.row < self.buffer_snapshot.max_point().row {
new_end.row += 1;
new_end.column = 0;
} else if new_start.row > 0 {
new_start.row -= 1;
new_start.column = self.buffer_snapshot.line_len(new_start.row);
}
}
range
new_start..new_end
}
fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
+5 -19
View File
@@ -1866,7 +1866,10 @@ impl Editor {
let snapshot = buffer.read(cx);
old_selections
.iter()
.map(|s| (s.id, s.goal, snapshot.anchor_after(s.end)))
.map(|s| {
let anchor = snapshot.anchor_after(s.end);
s.map(|_| anchor.clone())
})
.collect::<Vec<_>>()
};
buffer.edit_with_autoindent(
@@ -1878,25 +1881,8 @@ impl Editor {
anchors
});
let selections = {
let snapshot = this.buffer.read(cx).read(cx);
selection_anchors
.into_iter()
.map(|(id, goal, position)| {
let position = position.to_offset(&snapshot);
Selection {
id,
start: position,
end: position,
goal,
reversed: false,
}
})
.collect()
};
this.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select(selections);
s.select_anchors(selection_anchors);
})
});
}
@@ -22,6 +22,13 @@ pub struct PendingSelection {
pub mode: SelectMode,
}
#[derive(Clone)]
pub enum LineMode {
None,
WithNewline,
WithoutNewline,
}
#[derive(Clone)]
pub struct SelectionsCollection {
display_map: ModelHandle<DisplayMap>,