editor: Remove buffer and display map fields from SelectionsCollection (#42175)

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-11-07 11:21:14 +01:00
committed by GitHub
parent c2416d6bab
commit 88a8e53696
18 changed files with 394 additions and 367 deletions
+7 -3
View File
@@ -315,11 +315,15 @@ impl ProjectDiagnosticsEditor {
cx: &mut Context<Self>,
retain_selections: bool,
) {
let buffer_ids = self.multibuffer.read(cx).all_buffer_ids();
let selected_buffers = self.editor.update(cx, |editor, cx| {
let snapshot = self
.editor
.update(cx, |editor, cx| editor.display_snapshot(cx));
let buffer = self.multibuffer.read(cx);
let buffer_ids = buffer.all_buffer_ids();
let selected_buffers = self.editor.update(cx, |editor, _| {
editor
.selections
.all_anchors(cx)
.all_anchors(&snapshot)
.iter()
.filter_map(|anchor| anchor.start.buffer_id)
.collect::<HashSet<_>>()
+6 -2
View File
@@ -156,7 +156,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
// Cursor is at the first diagnostic
editor.update(cx, |editor, cx| {
assert_eq!(
editor.selections.display_ranges(cx),
editor
.selections
.display_ranges(&editor.display_snapshot(cx)),
[DisplayPoint::new(DisplayRow(3), 8)..DisplayPoint::new(DisplayRow(3), 8)]
);
});
@@ -232,7 +234,9 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
// Cursor keeps its position.
editor.update(cx, |editor, cx| {
assert_eq!(
editor.selections.display_ranges(cx),
editor
.selections
.display_ranges(&editor.display_snapshot(cx)),
[DisplayPoint::new(DisplayRow(8), 8)..DisplayPoint::new(DisplayRow(8), 8)]
);
});
@@ -63,6 +63,14 @@ pub struct BlockSnapshot {
pub(super) excerpt_header_height: u32,
}
impl Deref for BlockSnapshot {
type Target = WrapSnapshot;
fn deref(&self) -> &Self::Target {
&self.wrap_snapshot
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CustomBlockId(pub usize);
@@ -630,6 +630,14 @@ pub struct FoldSnapshot {
pub version: usize,
}
impl Deref for FoldSnapshot {
type Target = InlaySnapshot;
fn deref(&self) -> &Self::Target {
&self.inlay_snapshot
}
}
impl FoldSnapshot {
pub fn buffer(&self) -> &MultiBufferSnapshot {
&self.inlay_snapshot.buffer
@@ -32,6 +32,14 @@ pub struct InlaySnapshot {
pub version: usize,
}
impl std::ops::Deref for InlaySnapshot {
type Target = MultiBufferSnapshot;
fn deref(&self) -> &Self::Target {
&self.buffer
}
}
#[derive(Clone, Debug)]
enum Transform {
Isomorphic(TextSummary),
+8
View File
@@ -167,6 +167,14 @@ pub struct TabSnapshot {
pub version: usize,
}
impl std::ops::Deref for TabSnapshot {
type Target = FoldSnapshot;
fn deref(&self) -> &Self::Target {
&self.fold_snapshot
}
}
impl TabSnapshot {
pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
&self.fold_snapshot.inlay_snapshot.buffer
@@ -43,6 +43,14 @@ pub struct WrapSnapshot {
interpolated: bool,
}
impl std::ops::Deref for WrapSnapshot {
type Target = TabSnapshot;
fn deref(&self) -> &Self::Target {
&self.tab_snapshot
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
struct Transform {
summary: TransformSummary,
+31 -23
View File
@@ -1843,7 +1843,7 @@ impl Editor {
})
});
let selections = SelectionsCollection::new(display_map.clone(), multi_buffer.clone());
let selections = SelectionsCollection::new();
let blink_manager = cx.new(|cx| {
let mut blink_manager = BlinkManager::new(CURSOR_BLINK_INTERVAL, cx);
@@ -2434,7 +2434,7 @@ impl Editor {
}
pub fn display_snapshot(&self, cx: &mut App) -> DisplaySnapshot {
self.selections.display_map(cx)
self.display_map.update(cx, |map, cx| map.snapshot(cx))
}
pub fn deploy_mouse_context_menu(
@@ -3366,11 +3366,13 @@ impl Editor {
other: Entity<Editor>,
cx: &mut Context<Self>,
) -> gpui::Subscription {
assert_eq!(self.buffer(), other.read(cx).buffer());
let other_selections = other.read(cx).selections.disjoint_anchors().to_vec();
if !other_selections.is_empty() {
self.selections.change_with(cx, |selections| {
selections.select_anchors(other_selections);
});
self.selections
.change_with(&self.display_snapshot(cx), |selections| {
selections.select_anchors(other_selections);
});
}
let other_subscription = cx.subscribe(&other, |this, other, other_evt, cx| {
@@ -3379,7 +3381,8 @@ impl Editor {
if other_selections.is_empty() {
return;
}
this.selections.change_with(cx, |selections| {
let snapshot = this.display_snapshot(cx);
this.selections.change_with(&snapshot, |selections| {
selections.select_anchors(other_selections);
});
}
@@ -3392,9 +3395,12 @@ impl Editor {
return;
}
other.update(cx, |other_editor, cx| {
other_editor.selections.change_with(cx, |selections| {
selections.select_anchors(these_selections);
})
let snapshot = other_editor.display_snapshot(cx);
other_editor
.selections
.change_with(&snapshot, |selections| {
selections.select_anchors(these_selections);
})
});
}
});
@@ -3410,13 +3416,14 @@ impl Editor {
effects: SelectionEffects,
window: &mut Window,
cx: &mut Context<Self>,
change: impl FnOnce(&mut MutableSelectionsCollection<'_>) -> R,
change: impl FnOnce(&mut MutableSelectionsCollection<'_, '_>) -> R,
) -> R {
let snapshot = self.display_snapshot(cx);
if let Some(state) = &mut self.deferred_selection_effects_state {
state.effects.scroll = effects.scroll.or(state.effects.scroll);
state.effects.completions = effects.completions;
state.effects.nav_history = effects.nav_history.or(state.effects.nav_history);
let (changed, result) = self.selections.change_with(cx, change);
let (changed, result) = self.selections.change_with(&snapshot, change);
state.changed |= changed;
return result;
}
@@ -3431,7 +3438,7 @@ impl Editor {
add_selections_state: self.add_selections_state.clone(),
},
};
let (changed, result) = self.selections.change_with(cx, change);
let (changed, result) = self.selections.change_with(&snapshot, change);
state.changed = state.changed || changed;
if self.defer_selection_effects {
self.deferred_selection_effects_state = Some(state);
@@ -16276,7 +16283,7 @@ impl Editor {
.map(|s| s.to_vec())
{
self.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map();
let map = s.display_snapshot();
s.select_display_ranges(selections.iter().map(|a| {
let point = a.to_display_point(&map);
point..point
@@ -16297,7 +16304,7 @@ impl Editor {
.map(|s| s.to_vec())
{
self.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map();
let map = s.display_snapshot();
s.select_display_ranges(selections.iter().map(|a| {
let point = a.to_display_point(&map);
point..point
@@ -18092,14 +18099,15 @@ impl Editor {
cx: &mut Context<Self>,
) {
let old_cursor_position = self.selections.newest_anchor().head();
self.selections.change_with(cx, |s| {
s.select_anchors(selections);
if let Some(pending_selection) = pending_selection {
s.set_pending(pending_selection, SelectMode::Character);
} else {
s.clear_pending();
}
});
self.selections
.change_with(&self.display_snapshot(cx), |s| {
s.select_anchors(selections);
if let Some(pending_selection) = pending_selection {
s.set_pending(pending_selection, SelectMode::Character);
} else {
s.clear_pending();
}
});
self.selections_did_change(
false,
&old_cursor_position,
@@ -20307,7 +20315,7 @@ impl Editor {
let locations = self
.selections
.all_anchors(cx)
.all_anchors(&self.display_snapshot(cx))
.iter()
.map(|selection| {
(
File diff suppressed because it is too large Load Diff
+57 -78
View File
@@ -1,33 +1,30 @@
use std::{
cell::Ref,
cmp, fmt, iter, mem,
ops::{Deref, DerefMut, Range, Sub},
sync::Arc,
};
use collections::HashMap;
use gpui::{App, Entity, Pixels};
use itertools::Itertools;
use gpui::Pixels;
use itertools::Itertools as _;
use language::{Bias, Point, Selection, SelectionGoal, TextDimension};
use util::post_inc;
use crate::{
Anchor, DisplayPoint, DisplayRow, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode,
ToOffset, ToPoint,
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
Anchor, DisplayPoint, DisplayRow, ExcerptId, MultiBufferSnapshot, SelectMode, ToOffset,
ToPoint,
display_map::{DisplaySnapshot, ToDisplayPoint},
movement::TextLayoutDetails,
};
#[derive(Debug, Clone)]
pub struct PendingSelection {
pub selection: Selection<Anchor>,
pub mode: SelectMode,
selection: Selection<Anchor>,
mode: SelectMode,
}
#[derive(Debug, Clone)]
pub struct SelectionsCollection {
display_map: Entity<DisplayMap>,
buffer: Entity<MultiBuffer>,
next_selection_id: usize,
line_mode: bool,
/// The non-pending, non-overlapping selections.
@@ -40,10 +37,8 @@ pub struct SelectionsCollection {
}
impl SelectionsCollection {
pub fn new(display_map: Entity<DisplayMap>, buffer: Entity<MultiBuffer>) -> Self {
pub fn new() -> Self {
Self {
display_map,
buffer,
next_selection_id: 1,
line_mode: false,
disjoint: Arc::default(),
@@ -62,14 +57,6 @@ impl SelectionsCollection {
}
}
pub fn display_map(&self, cx: &mut App) -> DisplaySnapshot {
self.display_map.update(cx, |map, cx| map.snapshot(cx))
}
fn buffer<'a>(&self, cx: &'a App) -> Ref<'a, MultiBufferSnapshot> {
self.buffer.read(cx).read(cx)
}
pub fn clone_state(&mut self, other: &SelectionsCollection) {
self.next_selection_id = other.next_selection_id;
self.line_mode = other.line_mode;
@@ -106,15 +93,14 @@ impl SelectionsCollection {
}
/// Non-overlapping selections using anchors, including the pending selection.
pub fn all_anchors(&self, cx: &mut App) -> Arc<[Selection<Anchor>]> {
pub fn all_anchors(&self, snapshot: &DisplaySnapshot) -> Arc<[Selection<Anchor>]> {
if self.pending.is_none() {
self.disjoint_anchors_arc()
} else {
let all_offset_selections = self.all::<usize>(&self.display_map(cx));
let buffer = self.buffer(cx);
let all_offset_selections = self.all::<usize>(snapshot);
all_offset_selections
.into_iter()
.map(|selection| selection_to_anchor_selection(selection, &buffer))
.map(|selection| selection_to_anchor_selection(selection, snapshot))
.collect()
}
}
@@ -354,16 +340,17 @@ impl SelectionsCollection {
}
#[cfg(any(test, feature = "test-support"))]
pub fn display_ranges(&self, cx: &mut App) -> Vec<Range<DisplayPoint>> {
let display_map = self.display_map(cx);
pub fn display_ranges(&self, display_snapshot: &DisplaySnapshot) -> Vec<Range<DisplayPoint>> {
self.disjoint_anchors_arc()
.iter()
.chain(self.pending_anchor())
.map(|s| {
if s.reversed {
s.end.to_display_point(&display_map)..s.start.to_display_point(&display_map)
s.end.to_display_point(display_snapshot)
..s.start.to_display_point(display_snapshot)
} else {
s.start.to_display_point(&display_map)..s.end.to_display_point(&display_map)
s.start.to_display_point(display_snapshot)
..s.end.to_display_point(display_snapshot)
}
})
.collect()
@@ -414,13 +401,13 @@ impl SelectionsCollection {
pub fn change_with<R>(
&mut self,
cx: &mut App,
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
snapshot: &DisplaySnapshot,
change: impl FnOnce(&mut MutableSelectionsCollection<'_, '_>) -> R,
) -> (bool, R) {
let mut mutable_collection = MutableSelectionsCollection {
snapshot,
collection: self,
selections_changed: false,
cx,
};
let result = change(&mut mutable_collection);
@@ -460,13 +447,13 @@ impl SelectionsCollection {
}
}
pub struct MutableSelectionsCollection<'a> {
pub struct MutableSelectionsCollection<'snap, 'a> {
collection: &'a mut SelectionsCollection,
snapshot: &'snap DisplaySnapshot,
selections_changed: bool,
cx: &'a mut App,
}
impl<'a> fmt::Debug for MutableSelectionsCollection<'a> {
impl<'snap, 'a> fmt::Debug for MutableSelectionsCollection<'snap, 'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MutableSelectionsCollection")
.field("collection", &self.collection)
@@ -475,13 +462,9 @@ impl<'a> fmt::Debug for MutableSelectionsCollection<'a> {
}
}
impl<'a> MutableSelectionsCollection<'a> {
pub fn display_map(&mut self) -> DisplaySnapshot {
self.collection.display_map(self.cx)
}
pub fn buffer(&self) -> Ref<'_, MultiBufferSnapshot> {
self.collection.buffer(self.cx)
impl<'snap, 'a> MutableSelectionsCollection<'snap, 'a> {
pub fn display_snapshot(&self) -> DisplaySnapshot {
self.snapshot.clone()
}
pub fn clear_disjoint(&mut self) {
@@ -512,12 +495,11 @@ impl<'a> MutableSelectionsCollection<'a> {
}
pub(crate) fn set_pending_anchor_range(&mut self, range: Range<Anchor>, mode: SelectMode) {
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
self.collection.pending = Some(PendingSelection {
selection: {
let mut start = range.start;
let mut end = range.end;
let reversed = if start.cmp(&end, &buffer).is_gt() {
let reversed = if start.cmp(&end, self.snapshot).is_gt() {
mem::swap(&mut start, &mut end);
true
} else {
@@ -557,7 +539,7 @@ impl<'a> MutableSelectionsCollection<'a> {
return true;
}
if !oldest.start.cmp(&oldest.end, &self.buffer()).is_eq() {
if !oldest.start.cmp(&oldest.end, self.snapshot).is_eq() {
let head = oldest.head();
oldest.start = head;
oldest.end = head;
@@ -573,10 +555,10 @@ impl<'a> MutableSelectionsCollection<'a> {
where
T: 'a + ToOffset + ToPoint + TextDimension + Ord + Sub<T, Output = T> + std::marker::Copy,
{
let display_map = self.display_map();
let display_map = self.display_snapshot();
let mut selections = self.collection.all(&display_map);
let mut start = range.start.to_offset(&self.buffer());
let mut end = range.end.to_offset(&self.buffer());
let mut start = range.start.to_offset(self.snapshot);
let mut end = range.end.to_offset(self.snapshot);
let reversed = if start > end {
mem::swap(&mut start, &mut end);
true
@@ -597,10 +579,9 @@ impl<'a> MutableSelectionsCollection<'a> {
where
T: ToOffset + std::marker::Copy + std::fmt::Debug,
{
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
let mut selections = selections
.into_iter()
.map(|selection| selection.map(|it| it.to_offset(&buffer)))
.map(|selection| selection.map(|it| it.to_offset(self.snapshot)))
.map(|mut selection| {
if selection.start > selection.end {
mem::swap(&mut selection.start, &mut selection.end);
@@ -629,14 +610,14 @@ impl<'a> MutableSelectionsCollection<'a> {
self.collection.disjoint = Arc::from_iter(
selections
.into_iter()
.map(|selection| selection_to_anchor_selection(selection, &buffer)),
.map(|selection| selection_to_anchor_selection(selection, self.snapshot)),
);
self.collection.pending = None;
self.selections_changed = true;
}
pub fn select_anchors(&mut self, selections: Vec<Selection<Anchor>>) {
let map = self.display_map();
let map = self.display_snapshot();
let resolved_selections =
resolve_selections_wrapping_blocks::<usize, _>(&selections, &map).collect::<Vec<_>>();
self.select(resolved_selections);
@@ -647,10 +628,9 @@ impl<'a> MutableSelectionsCollection<'a> {
I: IntoIterator<Item = Range<T>>,
T: ToOffset,
{
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
let ranges = ranges
.into_iter()
.map(|range| range.start.to_offset(&buffer)..range.end.to_offset(&buffer));
.map(|range| range.start.to_offset(self.snapshot)..range.end.to_offset(self.snapshot));
self.select_offset_ranges(ranges);
}
@@ -686,13 +666,12 @@ impl<'a> MutableSelectionsCollection<'a> {
where
I: IntoIterator<Item = Range<Anchor>>,
{
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
let selections = ranges
.into_iter()
.map(|range| {
let mut start = range.start;
let mut end = range.end;
let reversed = if start.cmp(&end, &buffer).is_gt() {
let reversed = if start.cmp(&end, self.snapshot).is_gt() {
mem::swap(&mut start, &mut end);
true
} else {
@@ -718,7 +697,6 @@ impl<'a> MutableSelectionsCollection<'a> {
where
T: IntoIterator<Item = Range<DisplayPoint>>,
{
let display_map = self.display_map();
let selections = ranges
.into_iter()
.map(|range| {
@@ -732,8 +710,8 @@ impl<'a> MutableSelectionsCollection<'a> {
};
Selection {
id: post_inc(&mut self.collection.next_selection_id),
start: start.to_point(&display_map),
end: end.to_point(&display_map),
start: start.to_point(self.snapshot),
end: end.to_point(self.snapshot),
reversed,
goal: SelectionGoal::None,
}
@@ -743,7 +721,6 @@ impl<'a> MutableSelectionsCollection<'a> {
}
pub fn reverse_selections(&mut self) {
let map = &self.display_map();
let mut new_selections: Vec<Selection<Point>> = Vec::new();
let disjoint = self.disjoint.clone();
for selection in disjoint
@@ -753,8 +730,14 @@ impl<'a> MutableSelectionsCollection<'a> {
{
new_selections.push(Selection {
id: self.new_selection_id(),
start: selection.start.to_display_point(map).to_point(map),
end: selection.end.to_display_point(map).to_point(map),
start: selection
.start
.to_display_point(self.snapshot)
.to_point(self.snapshot),
end: selection
.end
.to_display_point(self.snapshot)
.to_point(self.snapshot),
reversed: selection.reversed,
goal: selection.goal,
});
@@ -767,7 +750,7 @@ impl<'a> MutableSelectionsCollection<'a> {
mut move_selection: impl FnMut(&DisplaySnapshot, &mut Selection<DisplayPoint>),
) {
let mut changed = false;
let display_map = self.display_map();
let display_map = self.display_snapshot();
let selections = self.collection.all_display(&display_map);
let selections = selections
.into_iter()
@@ -791,22 +774,20 @@ impl<'a> MutableSelectionsCollection<'a> {
mut move_selection: impl FnMut(&MultiBufferSnapshot, &mut Selection<usize>),
) {
let mut changed = false;
let snapshot = self.buffer().clone();
let display_map = self.display_map();
let display_map = self.display_snapshot();
let selections = self
.collection
.all::<usize>(&display_map)
.into_iter()
.map(|selection| {
let mut moved_selection = selection.clone();
move_selection(&snapshot, &mut moved_selection);
move_selection(self.snapshot, &mut moved_selection);
if selection != moved_selection {
changed = true;
}
moved_selection
})
.collect();
drop(snapshot);
if changed {
self.select(selections)
@@ -858,11 +839,10 @@ impl<'a> MutableSelectionsCollection<'a> {
&mut self,
find_replacement_cursors: impl FnOnce(&DisplaySnapshot) -> Vec<DisplayPoint>,
) {
let display_map = self.display_map();
let new_selections = find_replacement_cursors(&display_map)
let new_selections = find_replacement_cursors(self.snapshot)
.into_iter()
.map(|cursor| {
let cursor_point = cursor.to_point(&display_map);
let cursor_point = cursor.to_point(self.snapshot);
Selection {
id: post_inc(&mut self.collection.next_selection_id),
start: cursor_point,
@@ -886,12 +866,11 @@ impl<'a> MutableSelectionsCollection<'a> {
let mut selections_with_lost_position = HashMap::default();
let anchors_with_status = {
let buffer = self.buffer();
let disjoint_anchors = self
.disjoint
.iter()
.flat_map(|selection| [&selection.start, &selection.end]);
buffer.refresh_anchors(disjoint_anchors)
self.snapshot.refresh_anchors(disjoint_anchors)
};
let adjusted_disjoint: Vec<_> = anchors_with_status
.chunks(2)
@@ -919,16 +898,16 @@ impl<'a> MutableSelectionsCollection<'a> {
.collect();
if !adjusted_disjoint.is_empty() {
let map = self.display_map();
let map = self.display_snapshot();
let resolved_selections =
resolve_selections_wrapping_blocks(adjusted_disjoint.iter(), &map).collect();
self.select::<usize>(resolved_selections);
}
if let Some(pending) = pending.as_mut() {
let buffer = self.buffer();
let anchors =
buffer.refresh_anchors([&pending.selection.start, &pending.selection.end]);
let anchors = self
.snapshot
.refresh_anchors([&pending.selection.start, &pending.selection.end]);
let (_, start, kept_start) = anchors[0];
let (_, end, kept_end) = anchors[1];
let kept_head = if pending.selection.reversed {
@@ -951,14 +930,14 @@ impl<'a> MutableSelectionsCollection<'a> {
}
}
impl Deref for MutableSelectionsCollection<'_> {
impl Deref for MutableSelectionsCollection<'_, '_> {
type Target = SelectionsCollection;
fn deref(&self) -> &Self::Target {
self.collection
}
}
impl DerefMut for MutableSelectionsCollection<'_> {
impl DerefMut for MutableSelectionsCollection<'_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.collection
}
+60 -24
View File
@@ -1685,7 +1685,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43)]
);
});
@@ -1696,7 +1698,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 11)..DisplayPoint::new(DisplayRow(3), 13)]
);
});
@@ -1707,7 +1711,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58)]
);
});
@@ -1718,7 +1724,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43)]
);
});
@@ -1729,7 +1737,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58)]
);
});
@@ -1740,7 +1750,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 11)..DisplayPoint::new(DisplayRow(3), 13)]
);
});
@@ -1751,7 +1763,9 @@ mod tests {
search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43)]
);
});
@@ -1772,7 +1786,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43)]
);
});
@@ -1793,7 +1809,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 11)..DisplayPoint::new(DisplayRow(3), 13)]
);
});
@@ -1814,7 +1832,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58)]
);
});
@@ -1835,7 +1855,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.select_next_match(&SelectNextMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43)]
);
});
@@ -1856,7 +1878,9 @@ mod tests {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.select_prev_match(&SelectPreviousMatch, window, cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58)]
);
});
@@ -1989,7 +2013,7 @@ mod tests {
"Initially, the editor should not be focused"
);
let initial_selections = editor.update(cx, |editor, cx| {
let initial_selections = editor.selections.display_ranges(cx);
let initial_selections = editor.selections.display_ranges(&editor.display_snapshot(cx));
assert_eq!(
initial_selections.len(), 1,
"Expected to have only one selection before adding carets to all matches, but got: {initial_selections:?}",
@@ -2008,7 +2032,7 @@ mod tests {
);
search_bar.update(cx, |search_bar, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
editor.update(cx, |editor, cx| editor.selections.display_ranges(&editor.display_snapshot(cx)));
assert_eq!(
all_selections.len(),
expected_query_matches_count,
@@ -2032,8 +2056,11 @@ mod tests {
"Should still have editor focused after SelectNextMatch"
);
search_bar.update(cx, |search_bar, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
let all_selections = editor.update(cx, |editor, cx| {
editor
.selections
.display_ranges(&editor.display_snapshot(cx))
});
assert_eq!(
all_selections.len(),
1,
@@ -2062,7 +2089,7 @@ mod tests {
);
search_bar.update(cx, |search_bar, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
editor.update(cx, |editor, cx| editor.selections.display_ranges(&editor.display_snapshot(cx)));
assert_eq!(
all_selections.len(),
expected_query_matches_count,
@@ -2087,8 +2114,11 @@ mod tests {
);
search_bar.update(cx, |search_bar, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
let all_selections = editor.update(cx, |editor, cx| {
editor
.selections
.display_ranges(&editor.display_snapshot(cx))
});
assert_eq!(
all_selections.len(),
1,
@@ -2130,7 +2160,7 @@ mod tests {
);
search_bar.update(cx, |search_bar, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
editor.update(cx, |editor, cx| editor.selections.display_ranges(&editor.display_snapshot(cx)));
assert_eq!(
all_selections, last_match_selections,
"Should not select anything new if there are no matches"
@@ -2194,8 +2224,11 @@ mod tests {
search_bar.select_all_matches(&SelectAllMatches, window, cx);
});
search_bar.update(cx, |_, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
let all_selections = editor.update(cx, |editor, cx| {
editor
.selections
.display_ranges(&editor.display_snapshot(cx))
});
assert_eq!(
all_selections.len(),
2,
@@ -2220,8 +2253,11 @@ mod tests {
search_bar.select_all_matches(&SelectAllMatches, window, cx);
});
search_bar.update(cx, |_, cx| {
let all_selections =
editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
let all_selections = editor.update(cx, |editor, cx| {
editor
.selections
.display_ranges(&editor.display_snapshot(cx))
});
assert_eq!(
all_selections.len(),
2,
+16 -16
View File
@@ -2526,7 +2526,7 @@ pub mod tests {
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
.update(cx, |editor, cx| editor.selections.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(2), 32)..DisplayPoint::new(DisplayRow(2), 35)]
);
@@ -2537,9 +2537,9 @@ pub mod tests {
.update(cx, |search_view, window, cx| {
assert_eq!(search_view.active_match_index, Some(1));
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(2), 37)..DisplayPoint::new(DisplayRow(2), 40)]
);
search_view.select_match(Direction::Next, window, cx);
@@ -2550,9 +2550,9 @@ pub mod tests {
.update(cx, |search_view, window, cx| {
assert_eq!(search_view.active_match_index, Some(2));
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(5), 6)..DisplayPoint::new(DisplayRow(5), 9)]
);
search_view.select_match(Direction::Next, window, cx);
@@ -2563,9 +2563,9 @@ pub mod tests {
.update(cx, |search_view, window, cx| {
assert_eq!(search_view.active_match_index, Some(0));
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(2), 32)..DisplayPoint::new(DisplayRow(2), 35)]
);
search_view.select_match(Direction::Prev, window, cx);
@@ -2576,9 +2576,9 @@ pub mod tests {
.update(cx, |search_view, window, cx| {
assert_eq!(search_view.active_match_index, Some(2));
assert_eq!(
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(5), 6)..DisplayPoint::new(DisplayRow(5), 9)]
);
search_view.select_match(Direction::Prev, window, cx);
@@ -2589,9 +2589,9 @@ pub mod tests {
.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.display_ranges(cx)),
search_view.results_editor.update(cx, |editor, cx| editor
.selections
.display_ranges(&editor.display_snapshot(cx))),
[DisplayPoint::new(DisplayRow(2), 37)..DisplayPoint::new(DisplayRow(2), 40)]
);
})
+1 -1
View File
@@ -38,7 +38,7 @@ impl Vim {
.map(|s| s.to_vec())
{
editor.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map();
let map = s.display_snapshot();
s.select_display_ranges(selections.iter().map(|a| {
let point = a.to_display_point(&map);
point..point
+2 -1
View File
@@ -682,8 +682,9 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
.disjoint_anchor_ranges()
.collect::<Vec<_>>()
});
let snapshot = editor.buffer().read(cx).snapshot(cx);
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
let end = Point::new(range.end.0, s.buffer().line_len(range.end));
let end = Point::new(range.end.0, snapshot.line_len(range.end));
s.select_ranges([end..Point::new(range.start.0, 0)]);
});
selections
+1 -1
View File
@@ -120,8 +120,8 @@ impl Vim {
editor.edit(edits, cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
editor.change_selections(Default::default(), window, cx, |s| {
let snapshot = s.buffer().clone();
s.select_ranges(new_selections.into_iter().map(|(anchor, len)| {
let offset = anchor.to_offset(&snapshot);
if action.before {
+1 -1
View File
@@ -1210,7 +1210,7 @@ impl Vim {
s.select_anchor_ranges(vec![pos..pos])
}
let snapshot = s.display_map();
let snapshot = s.display_snapshot();
if let Some(pending) = s.pending_anchor_mut()
&& pending.reversed
&& mode.is_visual()
+2 -2
View File
@@ -179,7 +179,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.update_editor(cx, |_, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map();
let map = s.display_snapshot();
let ranges = ranges
.into_iter()
.map(|(start, end, reversed)| {
@@ -304,7 +304,7 @@ impl Vim {
) {
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Default::default(), window, cx, |s| {
let map = &s.display_map();
let map = &s.display_snapshot();
let mut head = s.newest_anchor().head().to_display_point(map);
let mut tail = s.oldest_anchor().tail().to_display_point(map);
+3 -1
View File
@@ -4072,7 +4072,9 @@ mod tests {
let editor = item.downcast::<Editor>().unwrap();
let (selections, scroll_position) = editor.update(cx, |editor, cx| {
(
editor.selections.display_ranges(cx),
editor
.selections
.display_ranges(&editor.display_snapshot(cx)),
editor.scroll_position(cx),
)
});