movement.rs

  1use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
  2use crate::{char_kind, CharKind, ToPoint};
  3use language::Point;
  4use std::ops::Range;
  5
  6pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
  7    if point.column() > 0 {
  8        *point.column_mut() -= 1;
  9    } else if point.row() > 0 {
 10        *point.row_mut() -= 1;
 11        *point.column_mut() = map.line_len(point.row());
 12    }
 13    map.clip_point(point, Bias::Left)
 14}
 15
 16pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
 17    let max_column = map.line_len(point.row());
 18    if point.column() < max_column {
 19        *point.column_mut() += 1;
 20    } else if point.row() < map.max_point().row() {
 21        *point.row_mut() += 1;
 22        *point.column_mut() = 0;
 23    }
 24    map.clip_point(point, Bias::Right)
 25}
 26
 27pub fn up(
 28    map: &DisplaySnapshot,
 29    start: DisplayPoint,
 30    goal: SelectionGoal,
 31    preserve_column_at_start: bool,
 32) -> (DisplayPoint, SelectionGoal) {
 33    up_by_rows(map, start, 1, goal, preserve_column_at_start)
 34}
 35
 36pub fn down(
 37    map: &DisplaySnapshot,
 38    start: DisplayPoint,
 39    goal: SelectionGoal,
 40    preserve_column_at_end: bool,
 41) -> (DisplayPoint, SelectionGoal) {
 42    down_by_rows(map, start, 1, goal, preserve_column_at_end)
 43}
 44
 45pub fn up_by_rows(
 46    map: &DisplaySnapshot,
 47    start: DisplayPoint,
 48    row_count: u32,
 49    goal: SelectionGoal,
 50    preserve_column_at_start: bool,
 51) -> (DisplayPoint, SelectionGoal) {
 52    let mut goal_column = if let SelectionGoal::Column(column) = goal {
 53        column
 54    } else {
 55        map.column_to_chars(start.row(), start.column())
 56    };
 57
 58    let prev_row = start.row().saturating_sub(row_count);
 59    let mut point = map.clip_point(
 60        DisplayPoint::new(prev_row, map.line_len(prev_row)),
 61        Bias::Left,
 62    );
 63    if point.row() < start.row() {
 64        *point.column_mut() = map.column_from_chars(point.row(), goal_column);
 65    } else if preserve_column_at_start {
 66        return (start, goal);
 67    } else {
 68        point = DisplayPoint::new(0, 0);
 69        goal_column = 0;
 70    }
 71
 72    let mut clipped_point = map.clip_point(point, Bias::Left);
 73    if clipped_point.row() < point.row() {
 74        clipped_point = map.clip_point(point, Bias::Right);
 75    }
 76    (clipped_point, SelectionGoal::Column(goal_column))
 77}
 78
 79pub fn down_by_rows(
 80    map: &DisplaySnapshot,
 81    start: DisplayPoint,
 82    row_count: u32,
 83    goal: SelectionGoal,
 84    preserve_column_at_end: bool,
 85) -> (DisplayPoint, SelectionGoal) {
 86    let mut goal_column = if let SelectionGoal::Column(column) = goal {
 87        column
 88    } else {
 89        map.column_to_chars(start.row(), start.column())
 90    };
 91
 92    let new_row = start.row() + row_count;
 93    let mut point = map.clip_point(DisplayPoint::new(new_row, 0), Bias::Right);
 94    if point.row() > start.row() {
 95        *point.column_mut() = map.column_from_chars(point.row(), goal_column);
 96    } else if preserve_column_at_end {
 97        return (start, goal);
 98    } else {
 99        point = map.max_point();
100        goal_column = map.column_to_chars(point.row(), point.column())
101    }
102
103    let mut clipped_point = map.clip_point(point, Bias::Right);
104    if clipped_point.row() > point.row() {
105        clipped_point = map.clip_point(point, Bias::Left);
106    }
107    (clipped_point, SelectionGoal::Column(goal_column))
108}
109
110pub fn line_beginning(
111    map: &DisplaySnapshot,
112    display_point: DisplayPoint,
113    stop_at_soft_boundaries: bool,
114) -> DisplayPoint {
115    let point = display_point.to_point(map);
116    let soft_line_start = map.clip_point(DisplayPoint::new(display_point.row(), 0), Bias::Right);
117    let line_start = map.prev_line_boundary(point).1;
118
119    if stop_at_soft_boundaries && display_point != soft_line_start {
120        soft_line_start
121    } else {
122        line_start
123    }
124}
125
126pub fn indented_line_beginning(
127    map: &DisplaySnapshot,
128    display_point: DisplayPoint,
129    stop_at_soft_boundaries: bool,
130) -> DisplayPoint {
131    let point = display_point.to_point(map);
132    let soft_line_start = map.clip_point(DisplayPoint::new(display_point.row(), 0), Bias::Right);
133    let indent_start = Point::new(
134        point.row,
135        map.buffer_snapshot.indent_size_for_line(point.row).len,
136    )
137    .to_display_point(map);
138    let line_start = map.prev_line_boundary(point).1;
139
140    if stop_at_soft_boundaries && soft_line_start > indent_start && display_point != soft_line_start
141    {
142        soft_line_start
143    } else if stop_at_soft_boundaries && display_point != indent_start {
144        indent_start
145    } else {
146        line_start
147    }
148}
149
150pub fn line_end(
151    map: &DisplaySnapshot,
152    display_point: DisplayPoint,
153    stop_at_soft_boundaries: bool,
154) -> DisplayPoint {
155    let soft_line_end = map.clip_point(
156        DisplayPoint::new(display_point.row(), map.line_len(display_point.row())),
157        Bias::Left,
158    );
159    if stop_at_soft_boundaries && display_point != soft_line_end {
160        soft_line_end
161    } else {
162        map.next_line_boundary(display_point.to_point(map)).1
163    }
164}
165
166pub fn previous_word_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
167    find_preceding_boundary(map, point, |left, right| {
168        (char_kind(left) != char_kind(right) && !right.is_whitespace()) || left == '\n'
169    })
170}
171
172pub fn previous_subword_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
173    find_preceding_boundary(map, point, |left, right| {
174        let is_word_start = char_kind(left) != char_kind(right) && !right.is_whitespace();
175        let is_subword_start =
176            left == '_' && right != '_' || left.is_lowercase() && right.is_uppercase();
177        is_word_start || is_subword_start || left == '\n'
178    })
179}
180
181pub fn next_word_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
182    find_boundary(map, point, |left, right| {
183        (char_kind(left) != char_kind(right) && !left.is_whitespace()) || right == '\n'
184    })
185}
186
187pub fn next_subword_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
188    find_boundary(map, point, |left, right| {
189        let is_word_end = (char_kind(left) != char_kind(right)) && !left.is_whitespace();
190        let is_subword_end =
191            left != '_' && right == '_' || left.is_lowercase() && right.is_uppercase();
192        is_word_end || is_subword_end || right == '\n'
193    })
194}
195
196/// Scans for a boundary preceding the given start point `from` until a boundary is found, indicated by the
197/// given predicate returning true. The predicate is called with the character to the left and right
198/// of the candidate boundary location, and will be called with `\n` characters indicating the start
199/// or end of a line.
200pub fn find_preceding_boundary(
201    map: &DisplaySnapshot,
202    from: DisplayPoint,
203    mut is_boundary: impl FnMut(char, char) -> bool,
204) -> DisplayPoint {
205    let mut start_column = 0;
206    let mut soft_wrap_row = from.row() + 1;
207
208    let mut prev = None;
209    for (ch, point) in map.reverse_chars_at(from) {
210        // Recompute soft_wrap_indent if the row has changed
211        if point.row() != soft_wrap_row {
212            soft_wrap_row = point.row();
213
214            if point.row() == 0 {
215                start_column = 0;
216            } else if let Some(indent) = map.soft_wrap_indent(point.row() - 1) {
217                start_column = indent;
218            }
219        }
220
221        // If the current point is in the soft_wrap, skip comparing it
222        if point.column() < start_column {
223            continue;
224        }
225
226        if let Some((prev_ch, prev_point)) = prev {
227            if is_boundary(ch, prev_ch) {
228                return prev_point;
229            }
230        }
231
232        prev = Some((ch, point));
233    }
234    DisplayPoint::zero()
235}
236
237/// Scans for a boundary preceding the given start point `from` until a boundary is found, indicated by the
238/// given predicate returning true. The predicate is called with the character to the left and right
239/// of the candidate boundary location, and will be called with `\n` characters indicating the start
240/// or end of a line. If no boundary is found, the start of the line is returned.
241pub fn find_preceding_boundary_in_line(
242    map: &DisplaySnapshot,
243    from: DisplayPoint,
244    mut is_boundary: impl FnMut(char, char) -> bool,
245) -> DisplayPoint {
246    let mut start_column = 0;
247    if from.row() > 0 {
248        if let Some(indent) = map.soft_wrap_indent(from.row() - 1) {
249            start_column = indent;
250        }
251    }
252
253    let mut prev = None;
254    for (ch, point) in map.reverse_chars_at(from) {
255        if let Some((prev_ch, prev_point)) = prev {
256            if is_boundary(ch, prev_ch) {
257                return prev_point;
258            }
259        }
260
261        if ch == '\n' || point.column() < start_column {
262            break;
263        }
264
265        prev = Some((ch, point));
266    }
267
268    prev.map(|(_, point)| point).unwrap_or(from)
269}
270
271/// Scans for a boundary following the given start point until a boundary is found, indicated by the
272/// given predicate returning true. The predicate is called with the character to the left and right
273/// of the candidate boundary location, and will be called with `\n` characters indicating the start
274/// or end of a line.
275pub fn find_boundary(
276    map: &DisplaySnapshot,
277    from: DisplayPoint,
278    mut is_boundary: impl FnMut(char, char) -> bool,
279) -> DisplayPoint {
280    let mut prev_ch = None;
281    for (ch, point) in map.chars_at(from) {
282        if let Some(prev_ch) = prev_ch {
283            if is_boundary(prev_ch, ch) {
284                return map.clip_point(point, Bias::Right);
285            }
286        }
287
288        prev_ch = Some(ch);
289    }
290    map.clip_point(map.max_point(), Bias::Right)
291}
292
293/// Scans for a boundary following the given start point until a boundary is found, indicated by the
294/// given predicate returning true. The predicate is called with the character to the left and right
295/// of the candidate boundary location, and will be called with `\n` characters indicating the start
296/// or end of a line. If no boundary is found, the end of the line is returned
297pub fn find_boundary_in_line(
298    map: &DisplaySnapshot,
299    from: DisplayPoint,
300    mut is_boundary: impl FnMut(char, char) -> bool,
301) -> DisplayPoint {
302    let mut prev = None;
303    for (ch, point) in map.chars_at(from) {
304        if let Some((prev_ch, _)) = prev {
305            if is_boundary(prev_ch, ch) {
306                return map.clip_point(point, Bias::Right);
307            }
308        }
309
310        prev = Some((ch, point));
311
312        if ch == '\n' {
313            break;
314        }
315    }
316
317    // Return the last position checked so that we give a point right before the newline or eof.
318    map.clip_point(prev.map(|(_, point)| point).unwrap_or(from), Bias::Right)
319}
320
321pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
322    let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
323    let text = &map.buffer_snapshot;
324    let next_char_kind = text.chars_at(ix).next().map(char_kind);
325    let prev_char_kind = text.reversed_chars_at(ix).next().map(char_kind);
326    prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
327}
328
329pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<DisplayPoint> {
330    let position = map
331        .clip_point(position, Bias::Left)
332        .to_offset(map, Bias::Left);
333    let (range, _) = map.buffer_snapshot.surrounding_word(position);
334    let start = range
335        .start
336        .to_point(&map.buffer_snapshot)
337        .to_display_point(map);
338    let end = range
339        .end
340        .to_point(&map.buffer_snapshot)
341        .to_display_point(map);
342    start..end
343}
344
345pub fn split_display_range_by_lines(
346    map: &DisplaySnapshot,
347    range: Range<DisplayPoint>,
348) -> Vec<Range<DisplayPoint>> {
349    let mut result = Vec::new();
350
351    let mut start = range.start;
352    // Loop over all the covered rows until the one containing the range end
353    for row in range.start.row()..range.end.row() {
354        let row_end_column = map.line_len(row);
355        let end = map.clip_point(DisplayPoint::new(row, row_end_column), Bias::Left);
356        if start != end {
357            result.push(start..end);
358        }
359        start = map.clip_point(DisplayPoint::new(row + 1, 0), Bias::Left);
360    }
361
362    // Add the final range from the start of the last end to the original range end.
363    result.push(start..range.end);
364
365    result
366}
367
368#[cfg(test)]
369mod tests {
370    use super::*;
371    use crate::{test::marked_display_snapshot, Buffer, DisplayMap, ExcerptRange, MultiBuffer};
372    use settings::Settings;
373
374    #[gpui::test]
375    fn test_previous_word_start(cx: &mut gpui::AppContext) {
376        cx.set_global(Settings::test(cx));
377        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
378            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
379            assert_eq!(
380                previous_word_start(&snapshot, display_points[1]),
381                display_points[0]
382            );
383        }
384
385        assert("\nˇ   ˇlorem", cx);
386        assert("ˇ\nˇ   lorem", cx);
387        assert("    ˇloremˇ", cx);
388        assert("ˇ    ˇlorem", cx);
389        assert("    ˇlorˇem", cx);
390        assert("\nlorem\nˇ   ˇipsum", cx);
391        assert("\n\nˇ\nˇ", cx);
392        assert("    ˇlorem  ˇipsum", cx);
393        assert("loremˇ-ˇipsum", cx);
394        assert("loremˇ-#$@ˇipsum", cx);
395        assert("ˇlorem_ˇipsum", cx);
396        assert(" ˇdefγˇ", cx);
397        assert(" ˇbcΔˇ", cx);
398        assert(" abˇ——ˇcd", cx);
399    }
400
401    #[gpui::test]
402    fn test_previous_subword_start(cx: &mut gpui::AppContext) {
403        cx.set_global(Settings::test(cx));
404        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
405            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
406            assert_eq!(
407                previous_subword_start(&snapshot, display_points[1]),
408                display_points[0]
409            );
410        }
411
412        // Subword boundaries are respected
413        assert("lorem_ˇipˇsum", cx);
414        assert("lorem_ˇipsumˇ", cx);
415        assert("ˇlorem_ˇipsum", cx);
416        assert("lorem_ˇipsum_ˇdolor", cx);
417        assert("loremˇIpˇsum", cx);
418        assert("loremˇIpsumˇ", cx);
419
420        // Word boundaries are still respected
421        assert("\nˇ   ˇlorem", cx);
422        assert("    ˇloremˇ", cx);
423        assert("    ˇlorˇem", cx);
424        assert("\nlorem\nˇ   ˇipsum", cx);
425        assert("\n\nˇ\nˇ", cx);
426        assert("    ˇlorem  ˇipsum", cx);
427        assert("loremˇ-ˇipsum", cx);
428        assert("loremˇ-#$@ˇipsum", cx);
429        assert(" ˇdefγˇ", cx);
430        assert(" bcˇΔˇ", cx);
431        assert(" ˇbcδˇ", cx);
432        assert(" abˇ——ˇcd", cx);
433    }
434
435    #[gpui::test]
436    fn test_find_preceding_boundary(cx: &mut gpui::AppContext) {
437        cx.set_global(Settings::test(cx));
438        fn assert(
439            marked_text: &str,
440            cx: &mut gpui::AppContext,
441            is_boundary: impl FnMut(char, char) -> bool,
442        ) {
443            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
444            assert_eq!(
445                find_preceding_boundary(&snapshot, display_points[1], is_boundary),
446                display_points[0]
447            );
448        }
449
450        assert("abcˇdef\ngh\nijˇk", cx, |left, right| {
451            left == 'c' && right == 'd'
452        });
453        assert("abcdef\nˇgh\nijˇk", cx, |left, right| {
454            left == '\n' && right == 'g'
455        });
456        let mut line_count = 0;
457        assert("abcdef\nˇgh\nijˇk", cx, |left, _| {
458            if left == '\n' {
459                line_count += 1;
460                line_count == 2
461            } else {
462                false
463            }
464        });
465    }
466
467    #[gpui::test]
468    fn test_next_word_end(cx: &mut gpui::AppContext) {
469        cx.set_global(Settings::test(cx));
470        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
471            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
472            assert_eq!(
473                next_word_end(&snapshot, display_points[0]),
474                display_points[1]
475            );
476        }
477
478        assert("\nˇ   loremˇ", cx);
479        assert("    ˇloremˇ", cx);
480        assert("    lorˇemˇ", cx);
481        assert("    loremˇ    ˇ\nipsum\n", cx);
482        assert("\nˇ\nˇ\n\n", cx);
483        assert("loremˇ    ipsumˇ   ", cx);
484        assert("loremˇ-ˇipsum", cx);
485        assert("loremˇ#$@-ˇipsum", cx);
486        assert("loremˇ_ipsumˇ", cx);
487        assert(" ˇbcΔˇ", cx);
488        assert(" abˇ——ˇcd", cx);
489    }
490
491    #[gpui::test]
492    fn test_next_subword_end(cx: &mut gpui::AppContext) {
493        cx.set_global(Settings::test(cx));
494        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
495            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
496            assert_eq!(
497                next_subword_end(&snapshot, display_points[0]),
498                display_points[1]
499            );
500        }
501
502        // Subword boundaries are respected
503        assert("loˇremˇ_ipsum", cx);
504        assert("ˇloremˇ_ipsum", cx);
505        assert("loremˇ_ipsumˇ", cx);
506        assert("loremˇ_ipsumˇ_dolor", cx);
507        assert("loˇremˇIpsum", cx);
508        assert("loremˇIpsumˇDolor", cx);
509
510        // Word boundaries are still respected
511        assert("\nˇ   loremˇ", cx);
512        assert("    ˇloremˇ", cx);
513        assert("    lorˇemˇ", cx);
514        assert("    loremˇ    ˇ\nipsum\n", cx);
515        assert("\nˇ\nˇ\n\n", cx);
516        assert("loremˇ    ipsumˇ   ", cx);
517        assert("loremˇ-ˇipsum", cx);
518        assert("loremˇ#$@-ˇipsum", cx);
519        assert("loremˇ_ipsumˇ", cx);
520        assert(" ˇbcˇΔ", cx);
521        assert(" abˇ——ˇcd", cx);
522    }
523
524    #[gpui::test]
525    fn test_find_boundary(cx: &mut gpui::AppContext) {
526        cx.set_global(Settings::test(cx));
527        fn assert(
528            marked_text: &str,
529            cx: &mut gpui::AppContext,
530            is_boundary: impl FnMut(char, char) -> bool,
531        ) {
532            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
533            assert_eq!(
534                find_boundary(&snapshot, display_points[0], is_boundary),
535                display_points[1]
536            );
537        }
538
539        assert("abcˇdef\ngh\nijˇk", cx, |left, right| {
540            left == 'j' && right == 'k'
541        });
542        assert("abˇcdef\ngh\nˇijk", cx, |left, right| {
543            left == '\n' && right == 'i'
544        });
545        let mut line_count = 0;
546        assert("abcˇdef\ngh\nˇijk", cx, |left, _| {
547            if left == '\n' {
548                line_count += 1;
549                line_count == 2
550            } else {
551                false
552            }
553        });
554    }
555
556    #[gpui::test]
557    fn test_surrounding_word(cx: &mut gpui::AppContext) {
558        cx.set_global(Settings::test(cx));
559        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
560            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
561            assert_eq!(
562                surrounding_word(&snapshot, display_points[1]),
563                display_points[0]..display_points[2]
564            );
565        }
566
567        assert("ˇˇloremˇ  ipsum", cx);
568        assert("ˇloˇremˇ  ipsum", cx);
569        assert("ˇloremˇˇ  ipsum", cx);
570        assert("loremˇ ˇ  ˇipsum", cx);
571        assert("lorem\nˇˇˇ\nipsum", cx);
572        assert("lorem\nˇˇipsumˇ", cx);
573        assert("lorem,ˇˇ ˇipsum", cx);
574        assert("ˇloremˇˇ, ipsum", cx);
575    }
576
577    #[gpui::test]
578    fn test_move_up_and_down_with_excerpts(cx: &mut gpui::AppContext) {
579        cx.set_global(Settings::test(cx));
580        let family_id = cx
581            .font_cache()
582            .load_family(&["Helvetica"], &Default::default())
583            .unwrap();
584        let font_id = cx
585            .font_cache()
586            .select_font(family_id, &Default::default())
587            .unwrap();
588
589        let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndefg\nhijkl\nmn", cx));
590        let multibuffer = cx.add_model(|cx| {
591            let mut multibuffer = MultiBuffer::new(0);
592            multibuffer.push_excerpts(
593                buffer.clone(),
594                [
595                    ExcerptRange {
596                        context: Point::new(0, 0)..Point::new(1, 4),
597                        primary: None,
598                    },
599                    ExcerptRange {
600                        context: Point::new(2, 0)..Point::new(3, 2),
601                        primary: None,
602                    },
603                ],
604                cx,
605            );
606            multibuffer
607        });
608        let display_map =
609            cx.add_model(|cx| DisplayMap::new(multibuffer, font_id, 14.0, None, 2, 2, cx));
610        let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
611
612        assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn");
613
614        // Can't move up into the first excerpt's header
615        assert_eq!(
616            up(
617                &snapshot,
618                DisplayPoint::new(2, 2),
619                SelectionGoal::Column(2),
620                false
621            ),
622            (DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
623        );
624        assert_eq!(
625            up(
626                &snapshot,
627                DisplayPoint::new(2, 0),
628                SelectionGoal::None,
629                false
630            ),
631            (DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
632        );
633
634        // Move up and down within first excerpt
635        assert_eq!(
636            up(
637                &snapshot,
638                DisplayPoint::new(3, 4),
639                SelectionGoal::Column(4),
640                false
641            ),
642            (DisplayPoint::new(2, 3), SelectionGoal::Column(4)),
643        );
644        assert_eq!(
645            down(
646                &snapshot,
647                DisplayPoint::new(2, 3),
648                SelectionGoal::Column(4),
649                false
650            ),
651            (DisplayPoint::new(3, 4), SelectionGoal::Column(4)),
652        );
653
654        // Move up and down across second excerpt's header
655        assert_eq!(
656            up(
657                &snapshot,
658                DisplayPoint::new(6, 5),
659                SelectionGoal::Column(5),
660                false
661            ),
662            (DisplayPoint::new(3, 4), SelectionGoal::Column(5)),
663        );
664        assert_eq!(
665            down(
666                &snapshot,
667                DisplayPoint::new(3, 4),
668                SelectionGoal::Column(5),
669                false
670            ),
671            (DisplayPoint::new(6, 5), SelectionGoal::Column(5)),
672        );
673
674        // Can't move down off the end
675        assert_eq!(
676            down(
677                &snapshot,
678                DisplayPoint::new(7, 0),
679                SelectionGoal::Column(0),
680                false
681            ),
682            (DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
683        );
684        assert_eq!(
685            down(
686                &snapshot,
687                DisplayPoint::new(7, 2),
688                SelectionGoal::Column(2),
689                false
690            ),
691            (DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
692        );
693    }
694}