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
196pub fn start_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint {
197    let point = display_point.to_point(map);
198    if point.row == 0 {
199        return map.max_point();
200    }
201
202    let mut found_non_blank_line = false;
203    for row in (0..point.row + 1).rev() {
204        let blank = map.buffer_snapshot.is_line_blank(row);
205        if found_non_blank_line && blank {
206            return Point::new(row, 0).to_display_point(map);
207        }
208
209        found_non_blank_line |= !blank;
210    }
211
212    DisplayPoint::zero()
213}
214
215pub fn end_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint {
216    let point = display_point.to_point(map);
217    if point.row == map.max_buffer_row() {
218        return DisplayPoint::zero();
219    }
220
221    let mut found_non_blank_line = false;
222    for row in point.row..map.max_buffer_row() + 1 {
223        let blank = map.buffer_snapshot.is_line_blank(row);
224        if found_non_blank_line && blank {
225            return Point::new(row, 0).to_display_point(map);
226        }
227
228        found_non_blank_line |= !blank;
229    }
230
231    map.max_point()
232}
233
234/// Scans for a boundary preceding the given start point `from` until a boundary is found, indicated by the
235/// given predicate returning true. The predicate is called with the character to the left and right
236/// of the candidate boundary location, and will be called with `\n` characters indicating the start
237/// or end of a line.
238pub fn find_preceding_boundary(
239    map: &DisplaySnapshot,
240    from: DisplayPoint,
241    mut is_boundary: impl FnMut(char, char) -> bool,
242) -> DisplayPoint {
243    let mut start_column = 0;
244    let mut soft_wrap_row = from.row() + 1;
245
246    let mut prev = None;
247    for (ch, point) in map.reverse_chars_at(from) {
248        // Recompute soft_wrap_indent if the row has changed
249        if point.row() != soft_wrap_row {
250            soft_wrap_row = point.row();
251
252            if point.row() == 0 {
253                start_column = 0;
254            } else if let Some(indent) = map.soft_wrap_indent(point.row() - 1) {
255                start_column = indent;
256            }
257        }
258
259        // If the current point is in the soft_wrap, skip comparing it
260        if point.column() < start_column {
261            continue;
262        }
263
264        if let Some((prev_ch, prev_point)) = prev {
265            if is_boundary(ch, prev_ch) {
266                return prev_point;
267            }
268        }
269
270        prev = Some((ch, point));
271    }
272    DisplayPoint::zero()
273}
274
275/// Scans for a boundary preceding the given start point `from` until a boundary is found, indicated by the
276/// given predicate returning true. The predicate is called with the character to the left and right
277/// of the candidate boundary location, and will be called with `\n` characters indicating the start
278/// or end of a line. If no boundary is found, the start of the line is returned.
279pub fn find_preceding_boundary_in_line(
280    map: &DisplaySnapshot,
281    from: DisplayPoint,
282    mut is_boundary: impl FnMut(char, char) -> bool,
283) -> DisplayPoint {
284    let mut start_column = 0;
285    if from.row() > 0 {
286        if let Some(indent) = map.soft_wrap_indent(from.row() - 1) {
287            start_column = indent;
288        }
289    }
290
291    let mut prev = None;
292    for (ch, point) in map.reverse_chars_at(from) {
293        if let Some((prev_ch, prev_point)) = prev {
294            if is_boundary(ch, prev_ch) {
295                return prev_point;
296            }
297        }
298
299        if ch == '\n' || point.column() < start_column {
300            break;
301        }
302
303        prev = Some((ch, point));
304    }
305
306    prev.map(|(_, point)| point).unwrap_or(from)
307}
308
309/// Scans for a boundary following the given start point until a boundary is found, indicated by the
310/// given predicate returning true. The predicate is called with the character to the left and right
311/// of the candidate boundary location, and will be called with `\n` characters indicating the start
312/// or end of a line.
313pub fn find_boundary(
314    map: &DisplaySnapshot,
315    from: DisplayPoint,
316    mut is_boundary: impl FnMut(char, char) -> bool,
317) -> DisplayPoint {
318    let mut prev_ch = None;
319    for (ch, point) in map.chars_at(from) {
320        if let Some(prev_ch) = prev_ch {
321            if is_boundary(prev_ch, ch) {
322                return map.clip_point(point, Bias::Right);
323            }
324        }
325
326        prev_ch = Some(ch);
327    }
328    map.clip_point(map.max_point(), Bias::Right)
329}
330
331/// Scans for a boundary following the given start point until a boundary is found, indicated by the
332/// given predicate returning true. The predicate is called with the character to the left and right
333/// of the candidate boundary location, and will be called with `\n` characters indicating the start
334/// or end of a line. If no boundary is found, the end of the line is returned
335pub fn find_boundary_in_line(
336    map: &DisplaySnapshot,
337    from: DisplayPoint,
338    mut is_boundary: impl FnMut(char, char) -> bool,
339) -> DisplayPoint {
340    let mut prev = None;
341    for (ch, point) in map.chars_at(from) {
342        if let Some((prev_ch, _)) = prev {
343            if is_boundary(prev_ch, ch) {
344                return map.clip_point(point, Bias::Right);
345            }
346        }
347
348        prev = Some((ch, point));
349
350        if ch == '\n' {
351            break;
352        }
353    }
354
355    // Return the last position checked so that we give a point right before the newline or eof.
356    map.clip_point(prev.map(|(_, point)| point).unwrap_or(from), Bias::Right)
357}
358
359pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
360    let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
361    let text = &map.buffer_snapshot;
362    let next_char_kind = text.chars_at(ix).next().map(char_kind);
363    let prev_char_kind = text.reversed_chars_at(ix).next().map(char_kind);
364    prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
365}
366
367pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<DisplayPoint> {
368    let position = map
369        .clip_point(position, Bias::Left)
370        .to_offset(map, Bias::Left);
371    let (range, _) = map.buffer_snapshot.surrounding_word(position);
372    let start = range
373        .start
374        .to_point(&map.buffer_snapshot)
375        .to_display_point(map);
376    let end = range
377        .end
378        .to_point(&map.buffer_snapshot)
379        .to_display_point(map);
380    start..end
381}
382
383pub fn split_display_range_by_lines(
384    map: &DisplaySnapshot,
385    range: Range<DisplayPoint>,
386) -> Vec<Range<DisplayPoint>> {
387    let mut result = Vec::new();
388
389    let mut start = range.start;
390    // Loop over all the covered rows until the one containing the range end
391    for row in range.start.row()..range.end.row() {
392        let row_end_column = map.line_len(row);
393        let end = map.clip_point(DisplayPoint::new(row, row_end_column), Bias::Left);
394        if start != end {
395            result.push(start..end);
396        }
397        start = map.clip_point(DisplayPoint::new(row + 1, 0), Bias::Left);
398    }
399
400    // Add the final range from the start of the last end to the original range end.
401    result.push(start..range.end);
402
403    result
404}
405
406#[cfg(test)]
407mod tests {
408    use super::*;
409    use crate::{test::marked_display_snapshot, Buffer, DisplayMap, ExcerptRange, MultiBuffer};
410    use settings::SettingsStore;
411
412    #[gpui::test]
413    fn test_previous_word_start(cx: &mut gpui::AppContext) {
414        init_test(cx);
415
416        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
417            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
418            assert_eq!(
419                previous_word_start(&snapshot, display_points[1]),
420                display_points[0]
421            );
422        }
423
424        assert("\nˇ   ˇlorem", cx);
425        assert("ˇ\nˇ   lorem", cx);
426        assert("    ˇloremˇ", cx);
427        assert("ˇ    ˇlorem", cx);
428        assert("    ˇlorˇem", cx);
429        assert("\nlorem\nˇ   ˇipsum", cx);
430        assert("\n\nˇ\nˇ", cx);
431        assert("    ˇlorem  ˇipsum", cx);
432        assert("loremˇ-ˇipsum", cx);
433        assert("loremˇ-#$@ˇipsum", cx);
434        assert("ˇlorem_ˇipsum", cx);
435        assert(" ˇdefγˇ", cx);
436        assert(" ˇbcΔˇ", cx);
437        assert(" abˇ——ˇcd", cx);
438    }
439
440    #[gpui::test]
441    fn test_previous_subword_start(cx: &mut gpui::AppContext) {
442        init_test(cx);
443
444        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
445            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
446            assert_eq!(
447                previous_subword_start(&snapshot, display_points[1]),
448                display_points[0]
449            );
450        }
451
452        // Subword boundaries are respected
453        assert("lorem_ˇipˇsum", cx);
454        assert("lorem_ˇipsumˇ", cx);
455        assert("ˇlorem_ˇipsum", cx);
456        assert("lorem_ˇipsum_ˇdolor", cx);
457        assert("loremˇIpˇsum", cx);
458        assert("loremˇIpsumˇ", cx);
459
460        // Word boundaries are still respected
461        assert("\nˇ   ˇlorem", cx);
462        assert("    ˇloremˇ", cx);
463        assert("    ˇlorˇem", cx);
464        assert("\nlorem\nˇ   ˇipsum", cx);
465        assert("\n\nˇ\nˇ", cx);
466        assert("    ˇlorem  ˇipsum", cx);
467        assert("loremˇ-ˇipsum", cx);
468        assert("loremˇ-#$@ˇipsum", cx);
469        assert(" ˇdefγˇ", cx);
470        assert(" bcˇΔˇ", cx);
471        assert(" ˇbcδˇ", cx);
472        assert(" abˇ——ˇcd", cx);
473    }
474
475    #[gpui::test]
476    fn test_find_preceding_boundary(cx: &mut gpui::AppContext) {
477        init_test(cx);
478
479        fn assert(
480            marked_text: &str,
481            cx: &mut gpui::AppContext,
482            is_boundary: impl FnMut(char, char) -> bool,
483        ) {
484            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
485            assert_eq!(
486                find_preceding_boundary(&snapshot, display_points[1], is_boundary),
487                display_points[0]
488            );
489        }
490
491        assert("abcˇdef\ngh\nijˇk", cx, |left, right| {
492            left == 'c' && right == 'd'
493        });
494        assert("abcdef\nˇgh\nijˇk", cx, |left, right| {
495            left == '\n' && right == 'g'
496        });
497        let mut line_count = 0;
498        assert("abcdef\nˇgh\nijˇk", cx, |left, _| {
499            if left == '\n' {
500                line_count += 1;
501                line_count == 2
502            } else {
503                false
504            }
505        });
506    }
507
508    #[gpui::test]
509    fn test_next_word_end(cx: &mut gpui::AppContext) {
510        init_test(cx);
511
512        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
513            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
514            assert_eq!(
515                next_word_end(&snapshot, display_points[0]),
516                display_points[1]
517            );
518        }
519
520        assert("\nˇ   loremˇ", cx);
521        assert("    ˇloremˇ", cx);
522        assert("    lorˇemˇ", cx);
523        assert("    loremˇ    ˇ\nipsum\n", cx);
524        assert("\nˇ\nˇ\n\n", cx);
525        assert("loremˇ    ipsumˇ   ", cx);
526        assert("loremˇ-ˇipsum", cx);
527        assert("loremˇ#$@-ˇipsum", cx);
528        assert("loremˇ_ipsumˇ", cx);
529        assert(" ˇbcΔˇ", cx);
530        assert(" abˇ——ˇcd", cx);
531    }
532
533    #[gpui::test]
534    fn test_next_subword_end(cx: &mut gpui::AppContext) {
535        init_test(cx);
536
537        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
538            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
539            assert_eq!(
540                next_subword_end(&snapshot, display_points[0]),
541                display_points[1]
542            );
543        }
544
545        // Subword boundaries are respected
546        assert("loˇremˇ_ipsum", cx);
547        assert("ˇloremˇ_ipsum", cx);
548        assert("loremˇ_ipsumˇ", cx);
549        assert("loremˇ_ipsumˇ_dolor", cx);
550        assert("loˇremˇIpsum", cx);
551        assert("loremˇIpsumˇDolor", cx);
552
553        // Word boundaries are still respected
554        assert("\nˇ   loremˇ", cx);
555        assert("    ˇloremˇ", cx);
556        assert("    lorˇemˇ", cx);
557        assert("    loremˇ    ˇ\nipsum\n", cx);
558        assert("\nˇ\nˇ\n\n", cx);
559        assert("loremˇ    ipsumˇ   ", cx);
560        assert("loremˇ-ˇipsum", cx);
561        assert("loremˇ#$@-ˇipsum", cx);
562        assert("loremˇ_ipsumˇ", cx);
563        assert(" ˇbcˇΔ", cx);
564        assert(" abˇ——ˇcd", cx);
565    }
566
567    #[gpui::test]
568    fn test_find_boundary(cx: &mut gpui::AppContext) {
569        init_test(cx);
570
571        fn assert(
572            marked_text: &str,
573            cx: &mut gpui::AppContext,
574            is_boundary: impl FnMut(char, char) -> bool,
575        ) {
576            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
577            assert_eq!(
578                find_boundary(&snapshot, display_points[0], is_boundary),
579                display_points[1]
580            );
581        }
582
583        assert("abcˇdef\ngh\nijˇk", cx, |left, right| {
584            left == 'j' && right == 'k'
585        });
586        assert("abˇcdef\ngh\nˇijk", cx, |left, right| {
587            left == '\n' && right == 'i'
588        });
589        let mut line_count = 0;
590        assert("abcˇdef\ngh\nˇijk", cx, |left, _| {
591            if left == '\n' {
592                line_count += 1;
593                line_count == 2
594            } else {
595                false
596            }
597        });
598    }
599
600    #[gpui::test]
601    fn test_surrounding_word(cx: &mut gpui::AppContext) {
602        init_test(cx);
603
604        fn assert(marked_text: &str, cx: &mut gpui::AppContext) {
605            let (snapshot, display_points) = marked_display_snapshot(marked_text, cx);
606            assert_eq!(
607                surrounding_word(&snapshot, display_points[1]),
608                display_points[0]..display_points[2]
609            );
610        }
611
612        assert("ˇˇloremˇ  ipsum", cx);
613        assert("ˇloˇremˇ  ipsum", cx);
614        assert("ˇloremˇˇ  ipsum", cx);
615        assert("loremˇ ˇ  ˇipsum", cx);
616        assert("lorem\nˇˇˇ\nipsum", cx);
617        assert("lorem\nˇˇipsumˇ", cx);
618        assert("lorem,ˇˇ ˇipsum", cx);
619        assert("ˇloremˇˇ, ipsum", cx);
620    }
621
622    #[gpui::test]
623    fn test_move_up_and_down_with_excerpts(cx: &mut gpui::AppContext) {
624        init_test(cx);
625
626        let family_id = cx
627            .font_cache()
628            .load_family(&["Helvetica"], &Default::default())
629            .unwrap();
630        let font_id = cx
631            .font_cache()
632            .select_font(family_id, &Default::default())
633            .unwrap();
634
635        let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndefg\nhijkl\nmn", cx));
636        let multibuffer = cx.add_model(|cx| {
637            let mut multibuffer = MultiBuffer::new(0);
638            multibuffer.push_excerpts(
639                buffer.clone(),
640                [
641                    ExcerptRange {
642                        context: Point::new(0, 0)..Point::new(1, 4),
643                        primary: None,
644                    },
645                    ExcerptRange {
646                        context: Point::new(2, 0)..Point::new(3, 2),
647                        primary: None,
648                    },
649                ],
650                cx,
651            );
652            multibuffer
653        });
654        let display_map =
655            cx.add_model(|cx| DisplayMap::new(multibuffer, font_id, 14.0, None, 2, 2, cx));
656        let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
657
658        assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn");
659
660        // Can't move up into the first excerpt's header
661        assert_eq!(
662            up(
663                &snapshot,
664                DisplayPoint::new(2, 2),
665                SelectionGoal::Column(2),
666                false
667            ),
668            (DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
669        );
670        assert_eq!(
671            up(
672                &snapshot,
673                DisplayPoint::new(2, 0),
674                SelectionGoal::None,
675                false
676            ),
677            (DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
678        );
679
680        // Move up and down within first excerpt
681        assert_eq!(
682            up(
683                &snapshot,
684                DisplayPoint::new(3, 4),
685                SelectionGoal::Column(4),
686                false
687            ),
688            (DisplayPoint::new(2, 3), SelectionGoal::Column(4)),
689        );
690        assert_eq!(
691            down(
692                &snapshot,
693                DisplayPoint::new(2, 3),
694                SelectionGoal::Column(4),
695                false
696            ),
697            (DisplayPoint::new(3, 4), SelectionGoal::Column(4)),
698        );
699
700        // Move up and down across second excerpt's header
701        assert_eq!(
702            up(
703                &snapshot,
704                DisplayPoint::new(6, 5),
705                SelectionGoal::Column(5),
706                false
707            ),
708            (DisplayPoint::new(3, 4), SelectionGoal::Column(5)),
709        );
710        assert_eq!(
711            down(
712                &snapshot,
713                DisplayPoint::new(3, 4),
714                SelectionGoal::Column(5),
715                false
716            ),
717            (DisplayPoint::new(6, 5), SelectionGoal::Column(5)),
718        );
719
720        // Can't move down off the end
721        assert_eq!(
722            down(
723                &snapshot,
724                DisplayPoint::new(7, 0),
725                SelectionGoal::Column(0),
726                false
727            ),
728            (DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
729        );
730        assert_eq!(
731            down(
732                &snapshot,
733                DisplayPoint::new(7, 2),
734                SelectionGoal::Column(2),
735                false
736            ),
737            (DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
738        );
739    }
740
741    fn init_test(cx: &mut gpui::AppContext) {
742        cx.set_global(SettingsStore::test(cx));
743        theme::init((), cx);
744        language::init(cx);
745        crate::init(cx);
746    }
747}