2021-12-08 17:24:00 +00:00
|
|
|
|
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
2022-01-28 10:23:14 +00:00
|
|
|
|
use crate::{char_kind, CharKind, ToPoint};
|
2021-03-10 04:00:51 +00:00
|
|
|
|
use anyhow::Result;
|
2022-02-04 16:52:50 +00:00
|
|
|
|
use language::Point;
|
2022-02-01 14:11:20 +00:00
|
|
|
|
use std::ops::Range;
|
2021-03-10 04:00:51 +00:00
|
|
|
|
|
2021-12-08 17:24:00 +00:00
|
|
|
|
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> {
|
2021-03-10 04:00:51 +00:00
|
|
|
|
if point.column() > 0 {
|
|
|
|
|
*point.column_mut() -= 1;
|
|
|
|
|
} else if point.row() > 0 {
|
|
|
|
|
*point.row_mut() -= 1;
|
2021-07-15 18:48:57 +00:00
|
|
|
|
*point.column_mut() = map.line_len(point.row());
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
2021-07-15 18:48:57 +00:00
|
|
|
|
Ok(map.clip_point(point, Bias::Left))
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:24:00 +00:00
|
|
|
|
pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> {
|
2021-07-15 18:48:57 +00:00
|
|
|
|
let max_column = map.line_len(point.row());
|
2021-03-10 04:00:51 +00:00
|
|
|
|
if point.column() < max_column {
|
2021-05-19 20:45:54 +00:00
|
|
|
|
*point.column_mut() += 1;
|
2021-07-15 18:48:57 +00:00
|
|
|
|
} else if point.row() < map.max_point().row() {
|
2021-03-10 04:00:51 +00:00
|
|
|
|
*point.row_mut() += 1;
|
|
|
|
|
*point.column_mut() = 0;
|
|
|
|
|
}
|
2021-07-15 18:48:57 +00:00
|
|
|
|
Ok(map.clip_point(point, Bias::Right))
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn up(
|
2021-12-08 17:24:00 +00:00
|
|
|
|
map: &DisplaySnapshot,
|
2021-12-16 19:16:48 +00:00
|
|
|
|
start: DisplayPoint,
|
2021-05-10 13:06:07 +00:00
|
|
|
|
goal: SelectionGoal,
|
|
|
|
|
) -> Result<(DisplayPoint, SelectionGoal)> {
|
2021-12-16 19:16:48 +00:00
|
|
|
|
let mut goal_column = if let SelectionGoal::Column(column) = goal {
|
2021-05-10 13:06:07 +00:00
|
|
|
|
column
|
|
|
|
|
} else {
|
2021-12-16 19:16:48 +00:00
|
|
|
|
map.column_to_chars(start.row(), start.column())
|
2021-05-10 13:06:07 +00:00
|
|
|
|
};
|
2021-05-19 05:32:34 +00:00
|
|
|
|
|
2021-12-16 19:16:48 +00:00
|
|
|
|
let prev_row = start.row().saturating_sub(1);
|
|
|
|
|
let mut point = map.clip_point(
|
|
|
|
|
DisplayPoint::new(prev_row, map.line_len(prev_row)),
|
|
|
|
|
Bias::Left,
|
|
|
|
|
);
|
|
|
|
|
if point.row() < start.row() {
|
|
|
|
|
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
|
|
|
|
} else {
|
|
|
|
|
point = DisplayPoint::new(0, 0);
|
|
|
|
|
goal_column = 0;
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 17:07:01 +00:00
|
|
|
|
let clip_bias = if point.column() == map.line_len(point.row()) {
|
|
|
|
|
Bias::Left
|
|
|
|
|
} else {
|
|
|
|
|
Bias::Right
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-27 22:50:06 +00:00
|
|
|
|
Ok((
|
2021-07-29 17:07:01 +00:00
|
|
|
|
map.clip_point(point, clip_bias),
|
2021-07-27 22:50:06 +00:00
|
|
|
|
SelectionGoal::Column(goal_column),
|
|
|
|
|
))
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn down(
|
2021-12-08 17:24:00 +00:00
|
|
|
|
map: &DisplaySnapshot,
|
2021-12-16 19:16:48 +00:00
|
|
|
|
start: DisplayPoint,
|
2021-05-10 13:06:07 +00:00
|
|
|
|
goal: SelectionGoal,
|
|
|
|
|
) -> Result<(DisplayPoint, SelectionGoal)> {
|
2021-12-16 19:16:48 +00:00
|
|
|
|
let mut goal_column = if let SelectionGoal::Column(column) = goal {
|
2021-05-10 13:06:07 +00:00
|
|
|
|
column
|
|
|
|
|
} else {
|
2021-12-16 19:16:48 +00:00
|
|
|
|
map.column_to_chars(start.row(), start.column())
|
2021-05-10 13:06:07 +00:00
|
|
|
|
};
|
2021-05-19 05:32:34 +00:00
|
|
|
|
|
2021-12-16 19:16:48 +00:00
|
|
|
|
let next_row = start.row() + 1;
|
|
|
|
|
let mut point = map.clip_point(DisplayPoint::new(next_row, 0), Bias::Right);
|
|
|
|
|
if point.row() > start.row() {
|
|
|
|
|
*point.column_mut() = map.column_from_chars(point.row(), goal_column);
|
|
|
|
|
} else {
|
|
|
|
|
point = map.max_point();
|
|
|
|
|
goal_column = map.column_to_chars(point.row(), point.column())
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 17:07:01 +00:00
|
|
|
|
let clip_bias = if point.column() == map.line_len(point.row()) {
|
|
|
|
|
Bias::Left
|
|
|
|
|
} else {
|
|
|
|
|
Bias::Right
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-27 22:50:06 +00:00
|
|
|
|
Ok((
|
2021-07-29 17:07:01 +00:00
|
|
|
|
map.clip_point(point, clip_bias),
|
2021-07-27 22:50:06 +00:00
|
|
|
|
SelectionGoal::Column(goal_column),
|
|
|
|
|
))
|
2021-03-10 04:00:51 +00:00
|
|
|
|
}
|
2021-04-29 07:52:03 +00:00
|
|
|
|
|
|
|
|
|
pub fn line_beginning(
|
2021-12-08 17:24:00 +00:00
|
|
|
|
map: &DisplaySnapshot,
|
2022-02-04 16:52:50 +00:00
|
|
|
|
display_point: DisplayPoint,
|
2022-02-04 17:10:30 +00:00
|
|
|
|
stop_at_soft_boundaries: bool,
|
2021-11-23 18:10:15 +00:00
|
|
|
|
) -> DisplayPoint {
|
2022-02-04 16:52:50 +00:00
|
|
|
|
let point = display_point.to_point(map);
|
|
|
|
|
let soft_line_start = map.clip_point(DisplayPoint::new(display_point.row(), 0), Bias::Right);
|
|
|
|
|
let indent_start = Point::new(
|
|
|
|
|
point.row,
|
|
|
|
|
map.buffer_snapshot.indent_column_for_line(point.row),
|
|
|
|
|
)
|
|
|
|
|
.to_display_point(map);
|
|
|
|
|
let line_start = map.prev_line_boundary(point).1;
|
|
|
|
|
|
2022-02-04 17:10:30 +00:00
|
|
|
|
if stop_at_soft_boundaries && soft_line_start > indent_start && display_point != soft_line_start
|
|
|
|
|
{
|
2022-02-04 16:52:50 +00:00
|
|
|
|
soft_line_start
|
2022-02-04 17:10:30 +00:00
|
|
|
|
} else if stop_at_soft_boundaries && display_point != indent_start {
|
2022-02-04 16:52:50 +00:00
|
|
|
|
indent_start
|
2021-04-29 07:52:03 +00:00
|
|
|
|
} else {
|
2022-02-04 16:52:50 +00:00
|
|
|
|
line_start
|
2021-04-29 07:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 17:10:30 +00:00
|
|
|
|
pub fn line_end(
|
|
|
|
|
map: &DisplaySnapshot,
|
|
|
|
|
display_point: DisplayPoint,
|
|
|
|
|
stop_at_soft_boundaries: bool,
|
|
|
|
|
) -> DisplayPoint {
|
2022-02-04 16:52:50 +00:00
|
|
|
|
let soft_line_end = map.clip_point(
|
|
|
|
|
DisplayPoint::new(display_point.row(), map.line_len(display_point.row())),
|
|
|
|
|
Bias::Left,
|
|
|
|
|
);
|
2022-02-04 17:10:30 +00:00
|
|
|
|
if stop_at_soft_boundaries && display_point != soft_line_end {
|
2022-02-04 16:52:50 +00:00
|
|
|
|
soft_line_end
|
2022-02-04 17:10:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
map.next_line_boundary(display_point.to_point(map)).1
|
2022-02-04 16:52:50 +00:00
|
|
|
|
}
|
2021-04-29 07:52:03 +00:00
|
|
|
|
}
|
2021-04-29 12:54:50 +00:00
|
|
|
|
|
2021-12-08 17:24:00 +00:00
|
|
|
|
pub fn prev_word_boundary(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
|
2021-07-29 20:00:51 +00:00
|
|
|
|
let mut line_start = 0;
|
|
|
|
|
if point.row() > 0 {
|
|
|
|
|
if let Some(indent) = map.soft_wrap_indent(point.row() - 1) {
|
|
|
|
|
line_start = indent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if point.column() == line_start {
|
2021-04-29 16:52:11 +00:00
|
|
|
|
if point.row() == 0 {
|
2021-11-23 15:19:11 +00:00
|
|
|
|
return DisplayPoint::new(0, 0);
|
2021-04-29 16:52:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
let row = point.row() - 1;
|
2021-09-23 00:00:57 +00:00
|
|
|
|
point = map.clip_point(DisplayPoint::new(row, map.line_len(row)), Bias::Left);
|
2021-04-29 16:52:11 +00:00
|
|
|
|
}
|
2021-09-23 00:00:57 +00:00
|
|
|
|
}
|
2021-04-29 16:52:11 +00:00
|
|
|
|
|
2021-09-23 00:00:57 +00:00
|
|
|
|
let mut boundary = DisplayPoint::new(point.row(), 0);
|
|
|
|
|
let mut column = 0;
|
|
|
|
|
let mut prev_char_kind = CharKind::Newline;
|
|
|
|
|
for c in map.chars_at(DisplayPoint::new(point.row(), 0)) {
|
|
|
|
|
if column >= point.column() {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-29 16:52:11 +00:00
|
|
|
|
|
2021-09-23 00:00:57 +00:00
|
|
|
|
let char_kind = char_kind(c);
|
|
|
|
|
if char_kind != prev_char_kind
|
|
|
|
|
&& char_kind != CharKind::Whitespace
|
|
|
|
|
&& char_kind != CharKind::Newline
|
|
|
|
|
{
|
|
|
|
|
*boundary.column_mut() = column;
|
2021-04-29 16:52:11 +00:00
|
|
|
|
}
|
2021-09-23 00:00:57 +00:00
|
|
|
|
|
|
|
|
|
prev_char_kind = char_kind;
|
|
|
|
|
column += c.len_utf8() as u32;
|
2021-04-29 16:52:11 +00:00
|
|
|
|
}
|
2021-11-23 15:19:11 +00:00
|
|
|
|
boundary
|
2021-04-29 12:54:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:24:00 +00:00
|
|
|
|
pub fn next_word_boundary(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
|
2021-09-23 00:00:57 +00:00
|
|
|
|
let mut prev_char_kind = None;
|
2021-08-02 12:11:31 +00:00
|
|
|
|
for c in map.chars_at(point) {
|
2021-09-23 00:00:57 +00:00
|
|
|
|
let char_kind = char_kind(c);
|
|
|
|
|
if let Some(prev_char_kind) = prev_char_kind {
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if prev_char_kind != char_kind
|
|
|
|
|
&& prev_char_kind != CharKind::Whitespace
|
|
|
|
|
&& prev_char_kind != CharKind::Newline
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-29 12:54:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
*point.row_mut() += 1;
|
|
|
|
|
*point.column_mut() = 0;
|
|
|
|
|
} else {
|
2021-05-18 03:45:14 +00:00
|
|
|
|
*point.column_mut() += c.len_utf8() as u32;
|
2021-04-29 12:54:50 +00:00
|
|
|
|
}
|
2021-09-23 00:00:57 +00:00
|
|
|
|
prev_char_kind = Some(char_kind);
|
2021-04-29 12:54:50 +00:00
|
|
|
|
}
|
2022-01-03 15:26:42 +00:00
|
|
|
|
map.clip_point(point, Bias::Right)
|
2021-11-23 15:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:24:00 +00:00
|
|
|
|
pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
|
2021-11-23 17:50:17 +00:00
|
|
|
|
let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
|
2021-11-30 21:29:04 +00:00
|
|
|
|
let text = &map.buffer_snapshot;
|
2021-11-23 17:50:17 +00:00
|
|
|
|
let next_char_kind = text.chars_at(ix).next().map(char_kind);
|
|
|
|
|
let prev_char_kind = text.reversed_chars_at(ix).next().map(char_kind);
|
|
|
|
|
prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 14:11:20 +00:00
|
|
|
|
pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<DisplayPoint> {
|
|
|
|
|
let position = map
|
|
|
|
|
.clip_point(position, Bias::Left)
|
|
|
|
|
.to_offset(map, Bias::Left);
|
|
|
|
|
let (range, _) = map.buffer_snapshot.surrounding_word(position);
|
|
|
|
|
let start = range
|
|
|
|
|
.start
|
|
|
|
|
.to_point(&map.buffer_snapshot)
|
|
|
|
|
.to_display_point(map);
|
|
|
|
|
let end = range
|
|
|
|
|
.end
|
|
|
|
|
.to_point(&map.buffer_snapshot)
|
|
|
|
|
.to_display_point(map);
|
|
|
|
|
start..end
|
2021-04-29 12:54:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-02 12:11:31 +00:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2022-02-10 01:23:56 +00:00
|
|
|
|
use crate::{Buffer, DisplayMap, MultiBuffer};
|
2021-12-16 19:16:48 +00:00
|
|
|
|
use language::Point;
|
|
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
|
fn test_move_up_and_down_with_excerpts(cx: &mut gpui::MutableAppContext) {
|
|
|
|
|
let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
|
|
|
|
|
let font_id = cx
|
|
|
|
|
.font_cache()
|
|
|
|
|
.select_font(family_id, &Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let buffer = cx.add_model(|cx| Buffer::new(0, "abc\ndefg\nhijkl\nmn", cx));
|
|
|
|
|
let multibuffer = cx.add_model(|cx| {
|
|
|
|
|
let mut multibuffer = MultiBuffer::new(0);
|
2022-02-10 01:56:06 +00:00
|
|
|
|
multibuffer.push_excerpts(
|
|
|
|
|
buffer.clone(),
|
|
|
|
|
[
|
|
|
|
|
Point::new(0, 0)..Point::new(1, 4),
|
|
|
|
|
Point::new(2, 0)..Point::new(3, 2),
|
|
|
|
|
],
|
|
|
|
|
cx,
|
|
|
|
|
);
|
2021-12-16 19:16:48 +00:00
|
|
|
|
multibuffer
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let display_map =
|
2022-02-09 21:51:52 +00:00
|
|
|
|
cx.add_model(|cx| DisplayMap::new(multibuffer, 2, font_id, 14.0, None, 2, 2, cx));
|
2021-12-16 19:16:48 +00:00
|
|
|
|
|
|
|
|
|
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
|
2022-02-09 21:51:52 +00:00
|
|
|
|
assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn");
|
2021-12-16 19:16:48 +00:00
|
|
|
|
|
|
|
|
|
// Can't move up into the first excerpt's header
|
|
|
|
|
assert_eq!(
|
|
|
|
|
up(&snapshot, DisplayPoint::new(2, 2), SelectionGoal::Column(2)).unwrap(),
|
|
|
|
|
(DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
up(&snapshot, DisplayPoint::new(2, 0), SelectionGoal::None).unwrap(),
|
|
|
|
|
(DisplayPoint::new(2, 0), SelectionGoal::Column(0)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Move up and down within first excerpt
|
|
|
|
|
assert_eq!(
|
|
|
|
|
up(&snapshot, DisplayPoint::new(3, 4), SelectionGoal::Column(4)).unwrap(),
|
|
|
|
|
(DisplayPoint::new(2, 3), SelectionGoal::Column(4)),
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
down(&snapshot, DisplayPoint::new(2, 3), SelectionGoal::Column(4)).unwrap(),
|
|
|
|
|
(DisplayPoint::new(3, 4), SelectionGoal::Column(4)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Move up and down across second excerpt's header
|
|
|
|
|
assert_eq!(
|
2022-02-09 21:51:52 +00:00
|
|
|
|
up(&snapshot, DisplayPoint::new(6, 5), SelectionGoal::Column(5)).unwrap(),
|
2021-12-16 19:16:48 +00:00
|
|
|
|
(DisplayPoint::new(3, 4), SelectionGoal::Column(5)),
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
down(&snapshot, DisplayPoint::new(3, 4), SelectionGoal::Column(5)).unwrap(),
|
2022-02-09 21:51:52 +00:00
|
|
|
|
(DisplayPoint::new(6, 5), SelectionGoal::Column(5)),
|
2021-12-16 19:16:48 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Can't move down off the end
|
|
|
|
|
assert_eq!(
|
2022-02-09 21:51:52 +00:00
|
|
|
|
down(&snapshot, DisplayPoint::new(7, 0), SelectionGoal::Column(0)).unwrap(),
|
|
|
|
|
(DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
|
2021-12-16 19:16:48 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2022-02-09 21:51:52 +00:00
|
|
|
|
down(&snapshot, DisplayPoint::new(7, 2), SelectionGoal::Column(2)).unwrap(),
|
|
|
|
|
(DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
|
2021-12-16 19:16:48 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2021-08-02 12:11:31 +00:00
|
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
|
fn test_prev_next_word_boundary_multibyte(cx: &mut gpui::MutableAppContext) {
|
2021-09-17 22:39:19 +00:00
|
|
|
|
let tab_size = 4;
|
|
|
|
|
let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
|
|
|
|
|
let font_id = cx
|
|
|
|
|
.font_cache()
|
|
|
|
|
.select_font(family_id, &Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
let font_size = 14.0;
|
|
|
|
|
|
2021-12-09 02:23:04 +00:00
|
|
|
|
let buffer = MultiBuffer::build_simple("a bcΔ defγ hi—jk", cx);
|
2022-02-09 21:51:52 +00:00
|
|
|
|
let display_map = cx
|
|
|
|
|
.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
|
2021-08-02 12:11:31 +00:00
|
|
|
|
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
prev_word_boundary(&snapshot, DisplayPoint::new(0, 12)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 7)
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
prev_word_boundary(&snapshot, DisplayPoint::new(0, 7)),
|
2021-09-23 00:00:57 +00:00
|
|
|
|
DisplayPoint::new(0, 2)
|
2021-08-02 12:11:31 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
prev_word_boundary(&snapshot, DisplayPoint::new(0, 6)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 2)
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
prev_word_boundary(&snapshot, DisplayPoint::new(0, 2)),
|
2021-09-23 00:00:57 +00:00
|
|
|
|
DisplayPoint::new(0, 0)
|
2021-08-02 12:11:31 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
prev_word_boundary(&snapshot, DisplayPoint::new(0, 1)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 0)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
next_word_boundary(&snapshot, DisplayPoint::new(0, 0)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 1)
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
next_word_boundary(&snapshot, DisplayPoint::new(0, 1)),
|
2021-09-23 00:00:57 +00:00
|
|
|
|
DisplayPoint::new(0, 6)
|
2021-08-02 12:11:31 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
next_word_boundary(&snapshot, DisplayPoint::new(0, 2)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 6)
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
next_word_boundary(&snapshot, DisplayPoint::new(0, 6)),
|
2021-09-23 00:00:57 +00:00
|
|
|
|
DisplayPoint::new(0, 12)
|
2021-08-02 12:11:31 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
2021-11-23 15:19:11 +00:00
|
|
|
|
next_word_boundary(&snapshot, DisplayPoint::new(0, 7)),
|
2021-08-02 12:11:31 +00:00
|
|
|
|
DisplayPoint::new(0, 12)
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-23 15:19:11 +00:00
|
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
|
fn test_surrounding_word(cx: &mut gpui::MutableAppContext) {
|
|
|
|
|
let tab_size = 4;
|
|
|
|
|
let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
|
|
|
|
|
let font_id = cx
|
|
|
|
|
.font_cache()
|
|
|
|
|
.select_font(family_id, &Default::default())
|
|
|
|
|
.unwrap();
|
|
|
|
|
let font_size = 14.0;
|
2021-12-09 02:23:04 +00:00
|
|
|
|
let buffer = MultiBuffer::build_simple("lorem ipsum dolor\n sit", cx);
|
2022-02-09 21:51:52 +00:00
|
|
|
|
let display_map = cx
|
|
|
|
|
.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
|
2021-11-23 15:19:11 +00:00
|
|
|
|
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 0)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 2)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 5)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 6)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 7)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 11)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 13)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 11)..DisplayPoint::new(0, 14),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 14)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 17)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(0, 19)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(1, 0)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(1, 0)..DisplayPoint::new(1, 4),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(1, 1)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(1, 0)..DisplayPoint::new(1, 4),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(1, 6)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(1, 4)..DisplayPoint::new(1, 7),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
surrounding_word(&snapshot, DisplayPoint::new(1, 7)),
|
2022-02-01 14:11:20 +00:00
|
|
|
|
DisplayPoint::new(1, 4)..DisplayPoint::new(1, 7),
|
2021-11-23 15:19:11 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2021-08-02 12:11:31 +00:00
|
|
|
|
}
|