mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 18:41:56 +03:00
store buffer and display_map model handles on selections collection
This commit is contained in:
parent
db0a9114c2
commit
de9dc27980
@ -5499,11 +5499,11 @@ mod tests {
|
|||||||
Some((worktree_id, "2.txt").into())
|
Some((worktree_id, "2.txt").into())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor_b2.read_with(cx_b, |editor, cx| editor.selected_ranges(cx)),
|
editor_b2.read_with(cx_b, |editor, cx| editor.selections.selected_ranges(cx)),
|
||||||
vec![2..3]
|
vec![2..3]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor_b1.read_with(cx_b, |editor, cx| editor.selected_ranges(cx)),
|
editor_b1.read_with(cx_b, |editor, cx| editor.selections.selected_ranges(cx)),
|
||||||
vec![0..1]
|
vec![0..1]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -5546,7 +5546,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
editor_b1
|
editor_b1
|
||||||
.condition(cx_b, |editor, cx| {
|
.condition(cx_b, |editor, cx| {
|
||||||
editor.selected_ranges(cx) == vec![1..1, 2..2]
|
editor.selections.selected_ranges(cx) == vec![1..1, 2..2]
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -5560,7 +5560,9 @@ mod tests {
|
|||||||
editor.set_scroll_position(vec2f(0., 100.), cx);
|
editor.set_scroll_position(vec2f(0., 100.), cx);
|
||||||
});
|
});
|
||||||
editor_b1
|
editor_b1
|
||||||
.condition(cx_b, |editor, cx| editor.selected_ranges(cx) == vec![3..3])
|
.condition(cx_b, |editor, cx| {
|
||||||
|
editor.selections.selected_ranges(cx) == vec![3..3]
|
||||||
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// After unfollowing, client B stops receiving updates from client A.
|
// After unfollowing, client B stops receiving updates from client A.
|
||||||
|
@ -419,9 +419,7 @@ impl ProjectDiagnosticsEditor {
|
|||||||
groups = self.path_states.get(path_ix)?.diagnostic_groups.as_slice();
|
groups = self.path_states.get(path_ix)?.diagnostic_groups.as_slice();
|
||||||
new_excerpt_ids_by_selection_id =
|
new_excerpt_ids_by_selection_id =
|
||||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| s.refresh());
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| s.refresh());
|
||||||
selections = editor
|
selections = editor.selections.interleaved::<usize>(cx);
|
||||||
.selections
|
|
||||||
.interleaved::<usize>(&editor.buffer().read(cx).read(cx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If any selection has lost its position, move it to start of the next primary diagnostic.
|
// If any selection has lost its position, move it to start of the next primary diagnostic.
|
||||||
@ -899,7 +897,7 @@ mod tests {
|
|||||||
// Cursor is at the first diagnostic
|
// Cursor is at the first diagnostic
|
||||||
view.editor.update(cx, |editor, cx| {
|
view.editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.selected_display_ranges(cx),
|
editor.selections.selected_display_ranges(cx),
|
||||||
[DisplayPoint::new(12, 6)..DisplayPoint::new(12, 6)]
|
[DisplayPoint::new(12, 6)..DisplayPoint::new(12, 6)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -1000,7 +998,7 @@ mod tests {
|
|||||||
// Cursor keeps its position.
|
// Cursor keeps its position.
|
||||||
view.editor.update(cx, |editor, cx| {
|
view.editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.selected_display_ranges(cx),
|
editor.selections.selected_display_ranges(cx),
|
||||||
[DisplayPoint::new(19, 6)..DisplayPoint::new(19, 6)]
|
[DisplayPoint::new(19, 6)..DisplayPoint::new(19, 6)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,7 @@ impl DiagnosticIndicator {
|
|||||||
fn update(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
|
fn update(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
|
||||||
let editor = editor.read(cx);
|
let editor = editor.read(cx);
|
||||||
let buffer = editor.buffer().read(cx);
|
let buffer = editor.buffer().read(cx);
|
||||||
let cursor_position = editor.selections.newest::<usize>(&buffer.read(cx)).head();
|
let cursor_position = editor.selections.newest::<usize>(cx).head();
|
||||||
let new_diagnostic = buffer
|
let new_diagnostic = buffer
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.diagnostics_in_range::<_, usize>(cursor_position..cursor_position, false)
|
.diagnostics_in_range::<_, usize>(cursor_position..cursor_position, false)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -959,7 +959,7 @@ impl Element for EditorElement {
|
|||||||
if view.show_local_selections {
|
if view.show_local_selections {
|
||||||
let local_selections = view
|
let local_selections = view
|
||||||
.selections
|
.selections
|
||||||
.interleaved_in_range(start_anchor..end_anchor, &display_map.buffer_snapshot);
|
.interleaved_in_range(start_anchor..end_anchor, cx);
|
||||||
for selection in &local_selections {
|
for selection in &local_selections {
|
||||||
let is_empty = selection.start == selection.end;
|
let is_empty = selection.start == selection.end;
|
||||||
let selection_start = snapshot.prev_line_boundary(selection.start).1;
|
let selection_start = snapshot.prev_line_boundary(selection.start).1;
|
||||||
@ -1043,7 +1043,7 @@ impl Element for EditorElement {
|
|||||||
|
|
||||||
let newest_selection_head = view
|
let newest_selection_head = view
|
||||||
.selections
|
.selections
|
||||||
.newest::<usize>(&snapshot.buffer_snapshot)
|
.newest::<usize>(cx)
|
||||||
.head()
|
.head()
|
||||||
.to_display_point(&snapshot);
|
.to_display_point(&snapshot);
|
||||||
|
|
||||||
|
@ -252,13 +252,13 @@ fn deserialize_selection(
|
|||||||
impl Item for Editor {
|
impl Item for Editor {
|
||||||
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
if let Ok(data) = data.downcast::<NavigationData>() {
|
if let Ok(data) = data.downcast::<NavigationData>() {
|
||||||
|
let newest_selection = self.selections.newest::<Point>(cx);
|
||||||
let buffer = self.buffer.read(cx).read(cx);
|
let buffer = self.buffer.read(cx).read(cx);
|
||||||
let offset = if buffer.can_resolve(&data.cursor_anchor) {
|
let offset = if buffer.can_resolve(&data.cursor_anchor) {
|
||||||
data.cursor_anchor.to_point(&buffer)
|
data.cursor_anchor.to_point(&buffer)
|
||||||
} else {
|
} else {
|
||||||
buffer.clip_point(data.cursor_position, Bias::Left)
|
buffer.clip_point(data.cursor_position, Bias::Left)
|
||||||
};
|
};
|
||||||
let newest_selection = self.selections.newest::<Point>(&buffer);
|
|
||||||
|
|
||||||
let scroll_top_anchor = if buffer.can_resolve(&data.scroll_top_anchor) {
|
let scroll_top_anchor = if buffer.can_resolve(&data.scroll_top_anchor) {
|
||||||
data.scroll_top_anchor
|
data.scroll_top_anchor
|
||||||
@ -465,7 +465,7 @@ impl CursorPosition {
|
|||||||
|
|
||||||
self.selected_count = 0;
|
self.selected_count = 0;
|
||||||
let mut last_selection: Option<Selection<usize>> = None;
|
let mut last_selection: Option<Selection<usize>> = None;
|
||||||
for selection in editor.selections.interleaved::<usize>(&buffer) {
|
for selection in editor.selections.interleaved::<usize>(cx) {
|
||||||
self.selected_count += selection.end - selection.start;
|
self.selected_count += selection.end - selection.start;
|
||||||
if last_selection
|
if last_selection
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -5,7 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::{ModelHandle, MutableAppContext};
|
use gpui::{AppContext, ModelHandle, MutableAppContext};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::{rope::TextDimension, Bias, Point, Selection, SelectionGoal, ToPoint};
|
use language::{rope::TextDimension, Bias, Point, Selection, SelectionGoal, ToPoint};
|
||||||
use util::post_inc;
|
use util::post_inc;
|
||||||
@ -22,14 +22,18 @@ pub struct PendingSelection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct SelectionsCollection {
|
pub struct SelectionsCollection {
|
||||||
|
display_map: ModelHandle<DisplayMap>,
|
||||||
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
pub next_selection_id: usize,
|
pub next_selection_id: usize,
|
||||||
disjoint: Arc<[Selection<Anchor>]>,
|
disjoint: Arc<[Selection<Anchor>]>,
|
||||||
pending: Option<PendingSelection>,
|
pending: Option<PendingSelection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectionsCollection {
|
impl SelectionsCollection {
|
||||||
pub fn new() -> Self {
|
pub fn new(display_map: ModelHandle<DisplayMap>, buffer: ModelHandle<MultiBuffer>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
display_map,
|
||||||
|
buffer,
|
||||||
next_selection_id: 1,
|
next_selection_id: 1,
|
||||||
disjoint: Arc::from([]),
|
disjoint: Arc::from([]),
|
||||||
pending: Some(PendingSelection {
|
pending: Some(PendingSelection {
|
||||||
@ -45,6 +49,14 @@ impl SelectionsCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_map(&self, cx: &mut MutableAppContext) -> DisplaySnapshot {
|
||||||
|
self.display_map.update(cx, |map, cx| map.snapshot(cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer(&self, cx: &AppContext) -> MultiBufferSnapshot {
|
||||||
|
self.buffer.read(cx).snapshot(cx)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn count<'a>(&self) -> usize {
|
pub fn count<'a>(&self) -> usize {
|
||||||
let mut count = self.disjoint.len();
|
let mut count = self.disjoint.len();
|
||||||
if self.pending.is_some() {
|
if self.pending.is_some() {
|
||||||
@ -65,25 +77,26 @@ impl SelectionsCollection {
|
|||||||
|
|
||||||
pub fn pending<D: TextDimension + Ord + Sub<D, Output = D>>(
|
pub fn pending<D: TextDimension + Ord + Sub<D, Output = D>>(
|
||||||
&self,
|
&self,
|
||||||
snapshot: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Option<Selection<D>> {
|
) -> Option<Selection<D>> {
|
||||||
self.pending_anchor()
|
self.pending_anchor()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|pending| pending.map(|p| p.summary::<D>(&snapshot)))
|
.map(|pending| pending.map(|p| p.summary::<D>(&self.buffer(cx))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pending_mode(&self) -> Option<SelectMode> {
|
pub fn pending_mode(&self) -> Option<SelectMode> {
|
||||||
self.pending.as_ref().map(|pending| pending.mode.clone())
|
self.pending.as_ref().map(|pending| pending.mode.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interleaved<'a, D>(&self, buffer: &MultiBufferSnapshot) -> Vec<Selection<D>>
|
pub fn interleaved<'a, D>(&self, cx: &AppContext) -> Vec<Selection<D>>
|
||||||
where
|
where
|
||||||
D: 'a + TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug,
|
D: 'a + TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
let disjoint_anchors = &self.disjoint;
|
let disjoint_anchors = &self.disjoint;
|
||||||
let mut disjoint = resolve_multiple::<D, _>(disjoint_anchors.iter(), &buffer).peekable();
|
let mut disjoint =
|
||||||
|
resolve_multiple::<D, _>(disjoint_anchors.iter(), &self.buffer(cx)).peekable();
|
||||||
|
|
||||||
let mut pending_opt = self.pending::<D>(&buffer);
|
let mut pending_opt = self.pending::<D>(cx);
|
||||||
|
|
||||||
iter::from_fn(move || {
|
iter::from_fn(move || {
|
||||||
if let Some(pending) = pending_opt.as_mut() {
|
if let Some(pending) = pending_opt.as_mut() {
|
||||||
@ -114,8 +127,9 @@ impl SelectionsCollection {
|
|||||||
pub fn interleaved_in_range<'a>(
|
pub fn interleaved_in_range<'a>(
|
||||||
&self,
|
&self,
|
||||||
range: Range<Anchor>,
|
range: Range<Anchor>,
|
||||||
buffer: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Vec<Selection<Point>> {
|
) -> Vec<Selection<Point>> {
|
||||||
|
let buffer = self.buffer(cx);
|
||||||
let start_ix = match self
|
let start_ix = match self
|
||||||
.disjoint
|
.disjoint
|
||||||
.binary_search_by(|probe| probe.end.cmp(&range.start, &buffer))
|
.binary_search_by(|probe| probe.end.cmp(&range.start, &buffer))
|
||||||
@ -162,9 +176,9 @@ impl SelectionsCollection {
|
|||||||
|
|
||||||
pub fn newest<D: TextDimension + Ord + Sub<D, Output = D>>(
|
pub fn newest<D: TextDimension + Ord + Sub<D, Output = D>>(
|
||||||
&self,
|
&self,
|
||||||
snapshot: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Selection<D> {
|
) -> Selection<D> {
|
||||||
resolve(self.newest_anchor(), snapshot)
|
resolve(self.newest_anchor(), &self.buffer(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn oldest_anchor(&self) -> &Selection<Anchor> {
|
pub fn oldest_anchor(&self) -> &Selection<Anchor> {
|
||||||
@ -177,36 +191,65 @@ impl SelectionsCollection {
|
|||||||
|
|
||||||
pub fn oldest<D: TextDimension + Ord + Sub<D, Output = D>>(
|
pub fn oldest<D: TextDimension + Ord + Sub<D, Output = D>>(
|
||||||
&self,
|
&self,
|
||||||
snapshot: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Selection<D> {
|
) -> Selection<D> {
|
||||||
resolve(self.oldest_anchor(), snapshot)
|
resolve(self.oldest_anchor(), &self.buffer(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn first<D: TextDimension + Ord + Sub<D, Output = D>>(
|
pub fn first<D: TextDimension + Ord + Sub<D, Output = D>>(
|
||||||
&self,
|
&self,
|
||||||
snapshot: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Selection<D> {
|
) -> Selection<D> {
|
||||||
self.interleaved(&snapshot).first().unwrap().clone()
|
self.interleaved(cx).first().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last<D: TextDimension + Ord + Sub<D, Output = D>>(
|
pub fn last<D: TextDimension + Ord + Sub<D, Output = D>>(
|
||||||
&self,
|
&self,
|
||||||
snapshot: &MultiBufferSnapshot,
|
cx: &AppContext,
|
||||||
) -> Selection<D> {
|
) -> Selection<D> {
|
||||||
self.interleaved(&snapshot).last().unwrap().clone()
|
self.interleaved(cx).last().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn selected_ranges<D: TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug>(
|
||||||
|
&self,
|
||||||
|
cx: &AppContext,
|
||||||
|
) -> Vec<Range<D>> {
|
||||||
|
self.interleaved::<D>(cx)
|
||||||
|
.iter()
|
||||||
|
.map(|s| {
|
||||||
|
if s.reversed {
|
||||||
|
s.end.clone()..s.start.clone()
|
||||||
|
} else {
|
||||||
|
s.start.clone()..s.end.clone()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn selected_display_ranges(&self, cx: &mut MutableAppContext) -> Vec<Range<DisplayPoint>> {
|
||||||
|
let display_map = self.display_map(cx);
|
||||||
|
self.disjoint_anchors()
|
||||||
|
.iter()
|
||||||
|
.chain(self.pending_anchor().as_ref())
|
||||||
|
.map(|s| {
|
||||||
|
if s.reversed {
|
||||||
|
s.end.to_display_point(&display_map)..s.start.to_display_point(&display_map)
|
||||||
|
} else {
|
||||||
|
s.start.to_display_point(&display_map)..s.end.to_display_point(&display_map)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn change_with<R>(
|
pub(crate) fn change_with<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
display_map: ModelHandle<DisplayMap>,
|
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
|
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
let mut mutable_collection = MutableSelectionsCollection {
|
let mut mutable_collection = MutableSelectionsCollection {
|
||||||
collection: self,
|
collection: self,
|
||||||
display_map,
|
|
||||||
buffer,
|
|
||||||
cx,
|
cx,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -221,12 +264,18 @@ impl SelectionsCollection {
|
|||||||
|
|
||||||
pub struct MutableSelectionsCollection<'a> {
|
pub struct MutableSelectionsCollection<'a> {
|
||||||
collection: &'a mut SelectionsCollection,
|
collection: &'a mut SelectionsCollection,
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
|
||||||
display_map: ModelHandle<DisplayMap>,
|
|
||||||
cx: &'a mut MutableAppContext,
|
cx: &'a mut MutableAppContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MutableSelectionsCollection<'a> {
|
impl<'a> MutableSelectionsCollection<'a> {
|
||||||
|
fn display_map(&mut self) -> DisplaySnapshot {
|
||||||
|
self.collection.display_map(self.cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer(&mut self) -> MultiBufferSnapshot {
|
||||||
|
self.collection.buffer(self.cx)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clear_disjoint(&mut self) {
|
pub fn clear_disjoint(&mut self) {
|
||||||
self.collection.disjoint = Arc::from([]);
|
self.collection.disjoint = Arc::from([]);
|
||||||
}
|
}
|
||||||
@ -303,19 +352,11 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
|
|
||||||
pub fn insert_range<T>(&mut self, range: Range<T>)
|
pub fn insert_range<T>(&mut self, range: Range<T>)
|
||||||
where
|
where
|
||||||
T: 'a
|
T: 'a + ToOffset + ToPoint + TextDimension + Ord + Sub<T, Output = T> + std::marker::Copy,
|
||||||
+ ToOffset
|
|
||||||
+ ToPoint
|
|
||||||
+ TextDimension
|
|
||||||
+ Ord
|
|
||||||
+ Sub<T, Output = T>
|
|
||||||
+ std::marker::Copy
|
|
||||||
+ std::fmt::Debug,
|
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
let mut selections = self.interleaved(self.cx);
|
||||||
let mut selections = self.interleaved(&buffer);
|
let mut start = range.start.to_offset(&self.buffer());
|
||||||
let mut start = range.start.to_offset(&buffer);
|
let mut end = range.end.to_offset(&self.buffer());
|
||||||
let mut end = range.end.to_offset(&buffer);
|
|
||||||
let reversed = if start > end {
|
let reversed = if start > end {
|
||||||
mem::swap(&mut start, &mut end);
|
mem::swap(&mut start, &mut end);
|
||||||
true
|
true
|
||||||
@ -440,7 +481,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
where
|
where
|
||||||
T: IntoIterator<Item = Range<DisplayPoint>>,
|
T: IntoIterator<Item = Range<DisplayPoint>>,
|
||||||
{
|
{
|
||||||
let display_map = self.display_map.update(self.cx, |map, cx| map.snapshot(cx));
|
let display_map = self.display_map();
|
||||||
let selections = ranges
|
let selections = ranges
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|range| {
|
.map(|range| {
|
||||||
@ -468,9 +509,9 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut move_selection: impl FnMut(&DisplaySnapshot, &mut Selection<DisplayPoint>),
|
mut move_selection: impl FnMut(&DisplaySnapshot, &mut Selection<DisplayPoint>),
|
||||||
) {
|
) {
|
||||||
let display_map = self.display_map.update(self.cx, |map, cx| map.snapshot(cx));
|
let display_map = self.display_map();
|
||||||
let selections = self
|
let selections = self
|
||||||
.interleaved::<Point>(&display_map.buffer_snapshot)
|
.interleaved::<Point>(self.cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
let mut selection = selection.map(|point| point.to_display_point(&display_map));
|
let mut selection = selection.map(|point| point.to_display_point(&display_map));
|
||||||
@ -514,7 +555,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut find_replacement_cursors: impl FnMut(&DisplaySnapshot) -> Vec<DisplayPoint>,
|
mut find_replacement_cursors: impl FnMut(&DisplaySnapshot) -> Vec<DisplayPoint>,
|
||||||
) {
|
) {
|
||||||
let display_map = self.display_map.update(self.cx, |map, cx| map.snapshot(cx));
|
let display_map = self.display_map();
|
||||||
let new_selections = find_replacement_cursors(&display_map)
|
let new_selections = find_replacement_cursors(&display_map)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|cursor| {
|
.map(|cursor| {
|
||||||
|
@ -54,5 +54,5 @@ pub fn assert_text_with_selections(
|
|||||||
let (unmarked_text, text_ranges) = marked_text_ranges(marked_text);
|
let (unmarked_text, text_ranges) = marked_text_ranges(marked_text);
|
||||||
|
|
||||||
assert_eq!(editor.text(cx), unmarked_text);
|
assert_eq!(editor.text(cx), unmarked_text);
|
||||||
assert_eq!(editor.selected_ranges(cx), text_ranges);
|
assert_eq!(editor.selections.selected_ranges(cx), text_ranges);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl GoToLine {
|
|||||||
let buffer = editor.buffer().read(cx).read(cx);
|
let buffer = editor.buffer().read(cx).read(cx);
|
||||||
(
|
(
|
||||||
Some(scroll_position),
|
Some(scroll_position),
|
||||||
editor.selections.newest(&buffer).head(),
|
editor.selections.newest(cx).head(),
|
||||||
buffer.max_point(),
|
buffer.max_point(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -172,7 +172,7 @@ impl PickerDelegate for OutlineView {
|
|||||||
|
|
||||||
let editor = self.active_editor.read(cx);
|
let editor = self.active_editor.read(cx);
|
||||||
let buffer = editor.buffer().read(cx).read(cx);
|
let buffer = editor.buffer().read(cx).read(cx);
|
||||||
let cursor_offset = editor.selections.newest::<usize>(&buffer).head();
|
let cursor_offset = editor.selections.newest::<usize>(cx).head();
|
||||||
selected_index = self
|
selected_index = self
|
||||||
.outline
|
.outline
|
||||||
.items
|
.items
|
||||||
|
@ -225,10 +225,7 @@ impl BufferSearchBar {
|
|||||||
let display_map = editor
|
let display_map = editor
|
||||||
.update(cx, |editor, cx| editor.snapshot(cx))
|
.update(cx, |editor, cx| editor.snapshot(cx))
|
||||||
.display_snapshot;
|
.display_snapshot;
|
||||||
let selection = editor
|
let selection = editor.read(cx).selections.newest::<usize>(cx);
|
||||||
.read(cx)
|
|
||||||
.selections
|
|
||||||
.newest::<usize>(&display_map.buffer_snapshot);
|
|
||||||
|
|
||||||
let mut text: String;
|
let mut text: String;
|
||||||
if selection.start == selection.end {
|
if selection.start == selection.end {
|
||||||
@ -732,7 +729,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(0));
|
assert_eq!(search_bar.active_match_index, Some(0));
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -743,7 +742,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -754,7 +755,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -765,7 +768,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -776,7 +781,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -787,7 +794,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -798,7 +807,9 @@ mod tests {
|
|||||||
search_bar.update(cx, |search_bar, cx| {
|
search_bar.update(cx, |search_bar, cx| {
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -817,7 +828,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(1));
|
assert_eq!(search_bar.active_match_index, Some(1));
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -836,7 +849,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(1));
|
assert_eq!(search_bar.active_match_index, Some(1));
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -855,7 +870,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(2));
|
assert_eq!(search_bar.active_match_index, Some(2));
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -874,7 +891,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(2));
|
assert_eq!(search_bar.active_match_index, Some(2));
|
||||||
search_bar.select_next_match(&SelectNextMatch, cx);
|
search_bar.select_next_match(&SelectNextMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -893,7 +912,9 @@ mod tests {
|
|||||||
assert_eq!(search_bar.active_match_index, Some(0));
|
assert_eq!(search_bar.active_match_index, Some(0));
|
||||||
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
search_bar.select_prev_match(&SelectPrevMatch, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
editor.update(cx, |editor, cx| editor
|
||||||
|
.selections
|
||||||
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -891,7 +891,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view
|
||||||
.results_editor
|
.results_editor
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.update(cx, |editor, cx| editor.selections.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
|
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -901,9 +901,9 @@ mod tests {
|
|||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
assert_eq!(search_view.active_match_index, Some(1));
|
assert_eq!(search_view.active_match_index, Some(1));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view.results_editor.update(cx, |editor, cx| editor
|
||||||
.results_editor
|
.selections
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
|
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
|
||||||
);
|
);
|
||||||
search_view.select_match(Direction::Next, cx);
|
search_view.select_match(Direction::Next, cx);
|
||||||
@ -912,9 +912,9 @@ mod tests {
|
|||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
assert_eq!(search_view.active_match_index, Some(2));
|
assert_eq!(search_view.active_match_index, Some(2));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view.results_editor.update(cx, |editor, cx| editor
|
||||||
.results_editor
|
.selections
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
|
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
|
||||||
);
|
);
|
||||||
search_view.select_match(Direction::Next, cx);
|
search_view.select_match(Direction::Next, cx);
|
||||||
@ -923,9 +923,9 @@ mod tests {
|
|||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
assert_eq!(search_view.active_match_index, Some(0));
|
assert_eq!(search_view.active_match_index, Some(0));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view.results_editor.update(cx, |editor, cx| editor
|
||||||
.results_editor
|
.selections
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
|
[DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35)]
|
||||||
);
|
);
|
||||||
search_view.select_match(Direction::Prev, cx);
|
search_view.select_match(Direction::Prev, cx);
|
||||||
@ -934,9 +934,9 @@ mod tests {
|
|||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
assert_eq!(search_view.active_match_index, Some(2));
|
assert_eq!(search_view.active_match_index, Some(2));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view.results_editor.update(cx, |editor, cx| editor
|
||||||
.results_editor
|
.selections
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
|
[DisplayPoint::new(5, 6)..DisplayPoint::new(5, 9)]
|
||||||
);
|
);
|
||||||
search_view.select_match(Direction::Prev, cx);
|
search_view.select_match(Direction::Prev, cx);
|
||||||
@ -945,9 +945,9 @@ mod tests {
|
|||||||
search_view.update(cx, |search_view, cx| {
|
search_view.update(cx, |search_view, cx| {
|
||||||
assert_eq!(search_view.active_match_index, Some(1));
|
assert_eq!(search_view.active_match_index, Some(1));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view.results_editor.update(cx, |editor, cx| editor
|
||||||
.results_editor
|
.selections
|
||||||
.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
|
.selected_display_ranges(cx)),
|
||||||
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
|
[DisplayPoint::new(2, 37)..DisplayPoint::new(2, 40)]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -200,7 +200,7 @@ impl<'a> VimTestContext<'a> {
|
|||||||
self.editor.read_with(self.cx, |editor, cx| {
|
self.editor.read_with(self.cx, |editor, cx| {
|
||||||
let (empty_selections, non_empty_selections): (Vec<_>, Vec<_>) = editor
|
let (empty_selections, non_empty_selections): (Vec<_>, Vec<_>) = editor
|
||||||
.selections
|
.selections
|
||||||
.interleaved::<usize>(&editor.buffer().read(cx).read(cx))
|
.interleaved::<usize>(cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.partition_map(|selection| {
|
.partition_map(|selection| {
|
||||||
if selection.is_empty() {
|
if selection.is_empty() {
|
||||||
|
@ -1180,7 +1180,7 @@ mod tests {
|
|||||||
let editor = item.downcast::<Editor>().unwrap();
|
let editor = item.downcast::<Editor>().unwrap();
|
||||||
let (selections, scroll_position) = editor.update(cx, |editor, cx| {
|
let (selections, scroll_position) = editor.update(cx, |editor, cx| {
|
||||||
(
|
(
|
||||||
editor.selected_display_ranges(cx),
|
editor.selections.selected_display_ranges(cx),
|
||||||
editor.scroll_position(cx),
|
editor.scroll_position(cx),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user