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