Rename selected_ranges and selected_display_ranges to remove redundant selected

This commit is contained in:
Keith Simmons 2022-05-12 16:04:27 -07:00
parent de9dc27980
commit c3a36e6d8a
8 changed files with 197 additions and 226 deletions

View file

@ -5499,11 +5499,11 @@ mod tests {
Some((worktree_id, "2.txt").into())
);
assert_eq!(
editor_b2.read_with(cx_b, |editor, cx| editor.selections.selected_ranges(cx)),
editor_b2.read_with(cx_b, |editor, cx| editor.selections.ranges(cx)),
vec![2..3]
);
assert_eq!(
editor_b1.read_with(cx_b, |editor, cx| editor.selections.selected_ranges(cx)),
editor_b1.read_with(cx_b, |editor, cx| editor.selections.ranges(cx)),
vec![0..1]
);
@ -5546,7 +5546,7 @@ mod tests {
});
editor_b1
.condition(cx_b, |editor, cx| {
editor.selections.selected_ranges(cx) == vec![1..1, 2..2]
editor.selections.ranges(cx) == vec![1..1, 2..2]
})
.await;
@ -5561,7 +5561,7 @@ mod tests {
});
editor_b1
.condition(cx_b, |editor, cx| {
editor.selections.selected_ranges(cx) == vec![3..3]
editor.selections.ranges(cx) == vec![3..3]
})
.await;

View file

@ -897,7 +897,7 @@ mod tests {
// Cursor is at the first diagnostic
view.editor.update(cx, |editor, cx| {
assert_eq!(
editor.selections.selected_display_ranges(cx),
editor.selections.display_ranges(cx),
[DisplayPoint::new(12, 6)..DisplayPoint::new(12, 6)]
);
});
@ -998,7 +998,7 @@ mod tests {
// Cursor keeps its position.
view.editor.update(cx, |editor, cx| {
assert_eq!(
editor.selections.selected_display_ranges(cx),
editor.selections.display_ranges(cx),
[DisplayPoint::new(19, 6)..DisplayPoint::new(19, 6)]
);
});

File diff suppressed because it is too large Load diff

View file

@ -129,6 +129,9 @@ impl SelectionsCollection {
range: Range<Anchor>,
cx: &AppContext,
) -> Vec<Selection<Point>> {
// TODO: Make sure pending selection is handled correctly here
// if it is interleaved properly, we can sue resolve_multiple
// to improve performance
let buffer = self.buffer(cx);
let start_ix = match self
.disjoint
@ -211,7 +214,7 @@ impl SelectionsCollection {
}
#[cfg(any(test, feature = "test-support"))]
pub fn selected_ranges<D: TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug>(
pub fn ranges<D: TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug>(
&self,
cx: &AppContext,
) -> Vec<Range<D>> {
@ -228,7 +231,7 @@ impl SelectionsCollection {
}
#[cfg(any(test, feature = "test-support"))]
pub fn selected_display_ranges(&self, cx: &mut MutableAppContext) -> Vec<Range<DisplayPoint>> {
pub fn display_ranges(&self, cx: &mut MutableAppContext) -> Vec<Range<DisplayPoint>> {
let display_map = self.display_map(cx);
self.disjoint_anchors()
.iter()

View file

@ -54,5 +54,5 @@ pub fn assert_text_with_selections(
let (unmarked_text, text_ranges) = marked_text_ranges(marked_text);
assert_eq!(editor.text(cx), unmarked_text);
assert_eq!(editor.selections.selected_ranges(cx), text_ranges);
assert_eq!(editor.selections.ranges(cx), text_ranges);
}

View file

@ -729,9 +729,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
@ -742,9 +740,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
@ -755,9 +751,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
@ -768,9 +762,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
@ -781,9 +773,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
@ -794,9 +784,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
@ -807,9 +795,7 @@ mod tests {
search_bar.update(cx, |search_bar, cx| {
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
@ -828,9 +814,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
@ -849,9 +833,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
@ -870,9 +852,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
@ -891,9 +871,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_next_match(&SelectNextMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
@ -912,9 +890,7 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_prev_match(&SelectPrevMatch, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});

View file

@ -891,7 +891,7 @@ mod tests {
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.selected_display_ranges(cx)),
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
);
@ -901,9 +901,9 @@ mod tests {
search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(1));
assert_eq!(
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
);
search_view.select_match(Direction::Next, cx);
@ -912,9 +912,9 @@ mod tests {
search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(2));
assert_eq!(
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
);
search_view.select_match(Direction::Next, cx);
@ -923,9 +923,9 @@ mod tests {
search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(0));
assert_eq!(
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
);
search_view.select_match(Direction::Prev, cx);
@ -934,9 +934,9 @@ mod tests {
search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(2));
assert_eq!(
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
);
search_view.select_match(Direction::Prev, cx);
@ -945,9 +945,9 @@ mod tests {
search_view.update(cx, |search_view, cx| {
assert_eq!(search_view.active_match_index, Some(1));
assert_eq!(
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.selected_display_ranges(cx)),
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
);
});

View file

@ -1180,7 +1180,7 @@ mod tests {
let editor = item.downcast::<Editor>().unwrap();
let (selections, scroll_position) = editor.update(cx, |editor, cx| {
(
editor.selections.selected_display_ranges(cx),
editor.selections.display_ranges(cx),
editor.scroll_position(cx),
)
});