@@ -5965,9 +5965,9 @@ async fn test_add_selection_above_below(cx: &mut TestAppContext) {
cx.assert_editor_state(indoc!(
r#"abc
defˇghi
-
+ ˇ
jk
- nlmˇo
+ nlmo
"#
));
@@ -5978,12 +5978,38 @@ async fn test_add_selection_above_below(cx: &mut TestAppContext) {
cx.assert_editor_state(indoc!(
r#"abc
defˇghi
+ ˇ
+ jkˇ
+ nlmo
+ "#
+ ));
- jk
+ cx.update_editor(|editor, window, cx| {
+ editor.add_selection_below(&Default::default(), window, cx);
+ });
+
+ cx.assert_editor_state(indoc!(
+ r#"abc
+ defˇghi
+ ˇ
+ jkˇ
nlmˇo
"#
));
+ cx.update_editor(|editor, window, cx| {
+ editor.add_selection_below(&Default::default(), window, cx);
+ });
+
+ cx.assert_editor_state(indoc!(
+ r#"abc
+ defˇghi
+ ˇ
+ jkˇ
+ nlmˇo
+ ˇ"#
+ ));
+
// change selections
cx.set_state(indoc!(
r#"abc
@@ -352,28 +352,32 @@ impl SelectionsCollection {
) -> Option<Selection<Point>> {
let is_empty = positions.start == positions.end;
let line_len = display_map.line_len(row);
-
let line = display_map.layout_row(row, text_layout_details);
-
let start_col = line.closest_index_for_x(positions.start) as u32;
- if start_col < line_len || (is_empty && positions.start == line.width) {
+
+ let (start, end) = if is_empty {
+ let point = DisplayPoint::new(row, std::cmp::min(start_col, line_len));
+ (point, point)
+ } else {
+ if start_col >= line_len {
+ return None;
+ }
let start = DisplayPoint::new(row, start_col);
let end_col = line.closest_index_for_x(positions.end) as u32;
let end = DisplayPoint::new(row, end_col);
+ (start, end)
+ };
- Some(Selection {
- id: post_inc(&mut self.next_selection_id),
- start: start.to_point(display_map),
- end: end.to_point(display_map),
- reversed,
- goal: SelectionGoal::HorizontalRange {
- start: positions.start.into(),
- end: positions.end.into(),
- },
- })
- } else {
- None
- }
+ Some(Selection {
+ id: post_inc(&mut self.next_selection_id),
+ start: start.to_point(display_map),
+ end: end.to_point(display_map),
+ reversed,
+ goal: SelectionGoal::HorizontalRange {
+ start: positions.start.into(),
+ end: positions.end.into(),
+ },
+ })
}
pub fn change_with<R>(