Passing tests and removed local argument. Also pulled autoscroll argument out to change_selections

This commit is contained in:
Keith Simmons 2022-05-12 14:18:46 -07:00
parent c9dcfff607
commit db0a9114c2
19 changed files with 351 additions and 397 deletions

View File

@ -3001,7 +3001,7 @@ mod tests {
// Type a completion trigger character as the guest.
editor_b.update(cx_b, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([13..13], None));
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input(&Input(".".into()), cx);
cx.focus(&editor_b);
});
@ -4213,8 +4213,8 @@ mod tests {
// Move cursor to a location that contains code actions.
editor_b.update(cx_b, |editor, cx| {
editor.change_selections(true, cx, |s| {
s.select_ranges([Point::new(1, 31)..Point::new(1, 31)], None)
editor.change_selections(None, cx, |s| {
s.select_ranges([Point::new(1, 31)..Point::new(1, 31)])
});
cx.focus(&editor_b);
});
@ -4452,7 +4452,7 @@ mod tests {
// Move cursor to a location that can be renamed.
let prepare_rename = editor_b.update(cx_b, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([7..7], None));
editor.change_selections(None, cx, |s| s.select_ranges([7..7]));
editor.rename(&Rename, cx).unwrap()
});
@ -5473,10 +5473,10 @@ mod tests {
// When client B starts following client A, all visible view states are replicated to client B.
editor_a1.update(cx_a, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([0..1], None))
editor.change_selections(None, cx, |s| s.select_ranges([0..1]))
});
editor_a2.update(cx_a, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([2..3], None))
editor.change_selections(None, cx, |s| s.select_ranges([2..3]))
});
workspace_b
.update(cx_b, |workspace, cx| {
@ -5542,7 +5542,7 @@ mod tests {
// Changes to client A's editor are reflected on client B.
editor_a1.update(cx_a, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([1..1, 2..2], None));
editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2]));
});
editor_b1
.condition(cx_b, |editor, cx| {
@ -5556,7 +5556,7 @@ mod tests {
.await;
editor_a1.update(cx_a, |editor, cx| {
editor.change_selections(true, cx, |s| s.select_ranges([3..3], None));
editor.change_selections(None, cx, |s| s.select_ranges([3..3]));
editor.set_scroll_position(vec2f(0., 100.), cx);
});
editor_b1

View File

@ -5,7 +5,7 @@ use collections::{BTreeSet, HashSet};
use editor::{
diagnostic_block_renderer,
display_map::{BlockDisposition, BlockId, BlockProperties, RenderBlock},
highlight_diagnostic_message, Editor, ExcerptId, MultiBuffer, ToOffset,
highlight_diagnostic_message, Autoscroll, Editor, ExcerptId, MultiBuffer, ToOffset,
};
use gpui::{
actions, elements::*, fonts::TextStyle, serde_json, AnyViewHandle, AppContext, Entity,
@ -418,7 +418,7 @@ impl ProjectDiagnosticsEditor {
} else {
groups = self.path_states.get(path_ix)?.diagnostic_groups.as_slice();
new_excerpt_ids_by_selection_id =
editor.change_selections(true, cx, |s| s.refresh());
editor.change_selections(Some(Autoscroll::Fit), cx, |s| s.refresh());
selections = editor
.selections
.interleaved::<usize>(&editor.buffer().read(cx).read(cx));
@ -444,8 +444,8 @@ impl ProjectDiagnosticsEditor {
}
}
}
editor.change_selections(true, cx, |s| {
s.select(selections, None);
editor.change_selections(None, cx, |s| {
s.select(selections);
});
Some(())
});

File diff suppressed because it is too large Load Diff

View File

@ -276,8 +276,8 @@ impl Item for Editor {
let nav_history = self.nav_history.take();
self.scroll_position = data.scroll_position;
self.scroll_top_anchor = scroll_top_anchor;
self.change_selections(true, cx, |s| {
s.select_ranges([offset..offset], Some(Autoscroll::Fit))
self.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_ranges([offset..offset])
});
self.nav_history = nav_history;
true

View File

@ -12,8 +12,7 @@ use util::post_inc;
use crate::{
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
Anchor, Autoscroll, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode,
ToOffset,
Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset,
};
#[derive(Clone)]
@ -79,10 +78,10 @@ impl SelectionsCollection {
pub fn interleaved<'a, D>(&self, buffer: &MultiBufferSnapshot) -> Vec<Selection<D>>
where
D: 'a + TextDimension + Ord + Sub<D, Output = D>,
D: 'a + TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug,
{
let anchor_disjoint = &self.disjoint;
let mut disjoint = resolve_multiple::<D, _>(anchor_disjoint.iter(), &buffer).peekable();
let disjoint_anchors = &self.disjoint;
let mut disjoint = resolve_multiple::<D, _>(disjoint_anchors.iter(), &buffer).peekable();
let mut pending_opt = self.pending::<D>(&buffer);
@ -197,36 +196,31 @@ impl SelectionsCollection {
self.interleaved(&snapshot).last().unwrap().clone()
}
// NOTE do not use. This should only be called from Editor::change_selections.
#[deprecated]
pub fn change_with<R>(
pub(crate) fn change_with<R>(
&mut self,
display_map: ModelHandle<DisplayMap>,
buffer: ModelHandle<MultiBuffer>,
cx: &mut MutableAppContext,
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
) -> (Option<Autoscroll>, R) {
) -> R {
let mut mutable_collection = MutableSelectionsCollection {
collection: self,
autoscroll: None,
display_map,
buffer,
cx,
};
let result = change(&mut mutable_collection);
assert!(
!mutable_collection.disjoint.is_empty() || mutable_collection.pending.is_some(),
"There must be at least one selection"
);
(mutable_collection.autoscroll, result)
result
}
}
pub struct MutableSelectionsCollection<'a> {
collection: &'a mut SelectionsCollection,
pub autoscroll: Option<Autoscroll>,
buffer: ModelHandle<MultiBuffer>,
display_map: ModelHandle<DisplayMap>,
cx: &'a mut MutableAppContext,
@ -307,7 +301,7 @@ impl<'a> MutableSelectionsCollection<'a> {
}
}
pub fn insert_range<T>(&mut self, range: Range<T>, autoscroll: Option<Autoscroll>)
pub fn insert_range<T>(&mut self, range: Range<T>)
where
T: 'a
+ ToOffset
@ -335,10 +329,10 @@ impl<'a> MutableSelectionsCollection<'a> {
reversed,
goal: SelectionGoal::None,
});
self.select(selections, autoscroll);
self.select(selections);
}
pub fn select<T>(&mut self, mut selections: Vec<Selection<T>>, autoscroll: Option<Autoscroll>)
pub fn select<T>(&mut self, mut selections: Vec<Selection<T>>)
where
T: ToOffset + ToPoint + Ord + std::marker::Copy + std::fmt::Debug,
{
@ -360,8 +354,6 @@ impl<'a> MutableSelectionsCollection<'a> {
}
}
self.autoscroll = autoscroll.or(self.autoscroll.take());
self.collection.disjoint = Arc::from_iter(selections.into_iter().map(|selection| {
let end_bias = if selection.end > selection.start {
Bias::Left
@ -380,46 +372,14 @@ impl<'a> MutableSelectionsCollection<'a> {
self.collection.pending = None;
}
pub fn select_anchors(
&mut self,
mut selections: Vec<Selection<Anchor>>,
autoscroll: Option<Autoscroll>,
) {
pub fn select_anchors(&mut self, selections: Vec<Selection<Anchor>>) {
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
selections.sort_unstable_by(|a, b| a.start.cmp(&b.start, &buffer));
// Merge overlapping selections.
let mut i = 1;
while i < selections.len() {
if selections[i - 1]
.end
.cmp(&selections[i].start, &buffer)
.is_ge()
{
let removed = selections.remove(i);
if removed.start.cmp(&selections[i - 1].start, &buffer).is_lt() {
selections[i - 1].start = removed.start;
}
if removed.end.cmp(&selections[i - 1].end, &buffer).is_gt() {
selections[i - 1].end = removed.end;
}
} else {
i += 1;
}
let resolved_selections =
resolve_multiple::<usize, _>(&selections, &buffer).collect::<Vec<_>>();
self.select(resolved_selections);
}
self.autoscroll = autoscroll.or(self.autoscroll.take());
self.collection.disjoint = Arc::from_iter(
selections
.into_iter()
.map(|selection| reset_biases(selection, &buffer)),
);
self.collection.pending = None;
}
pub fn select_ranges<I, T>(&mut self, ranges: I, autoscroll: Option<Autoscroll>)
pub fn select_ranges<I, T>(&mut self, ranges: I)
where
I: IntoIterator<Item = Range<T>>,
T: ToOffset,
@ -446,14 +406,10 @@ impl<'a> MutableSelectionsCollection<'a> {
})
.collect::<Vec<_>>();
self.select(selections, autoscroll)
self.select(selections)
}
pub fn select_anchor_ranges<I: IntoIterator<Item = Range<Anchor>>>(
&mut self,
ranges: I,
autoscroll: Option<Autoscroll>,
) {
pub fn select_anchor_ranges<I: IntoIterator<Item = Range<Anchor>>>(&mut self, ranges: I) {
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
let selections = ranges
.into_iter()
@ -476,7 +432,7 @@ impl<'a> MutableSelectionsCollection<'a> {
})
.collect::<Vec<_>>();
self.select_anchors(selections, autoscroll)
self.select_anchors(selections)
}
#[cfg(any(test, feature = "test-support"))]
@ -505,7 +461,7 @@ impl<'a> MutableSelectionsCollection<'a> {
}
})
.collect();
self.select(selections, None);
self.select(selections);
}
pub fn move_with(
@ -523,7 +479,7 @@ impl<'a> MutableSelectionsCollection<'a> {
})
.collect();
self.select(selections, Some(Autoscroll::Fit))
self.select(selections)
}
pub fn move_heads_with(
@ -572,7 +528,7 @@ impl<'a> MutableSelectionsCollection<'a> {
}
})
.collect();
self.select(new_selections, None);
self.select(new_selections);
}
/// Compute new ranges for any selections that were located in excerpts that have
@ -620,10 +576,7 @@ impl<'a> MutableSelectionsCollection<'a> {
.collect();
if !adjusted_disjoint.is_empty() {
self.select::<usize>(
resolve_multiple(adjusted_disjoint.iter(), &buffer).collect(),
None,
);
self.select::<usize>(resolve_multiple(adjusted_disjoint.iter(), &buffer).collect());
}
if let Some(pending) = pending.as_mut() {
@ -665,12 +618,16 @@ pub fn resolve_multiple<'a, D, I>(
snapshot: &MultiBufferSnapshot,
) -> impl 'a + Iterator<Item = Selection<D>>
where
D: TextDimension + Ord + Sub<D, Output = D>,
D: TextDimension + Ord + Sub<D, Output = D> + std::fmt::Debug,
I: 'a + IntoIterator<Item = &'a Selection<Anchor>>,
{
let (to_summarize, selections) = selections.into_iter().tee();
let mut summaries = snapshot
.summaries_for_anchors::<D, _>(to_summarize.flat_map(|s| [&s.start, &s.end]))
.summaries_for_anchors::<D, _>(
to_summarize
.flat_map(|s| [&s.start, &s.end])
.collect::<Vec<_>>(),
)
.into_iter();
selections.map(move |s| Selection {
id: s.id,
@ -692,7 +649,7 @@ fn reset_biases(
mut selection: Selection<Anchor>,
buffer: &MultiBufferSnapshot,
) -> Selection<Anchor> {
let end_bias = if selection.end.cmp(&selection.start, buffer).is_gt() {
let end_bias = if selection.end.to_offset(buffer) > selection.start.to_offset(buffer) {
Bias::Left
} else {
Bias::Right

View File

@ -43,7 +43,7 @@ pub fn marked_display_snapshot(
pub fn select_ranges(editor: &mut Editor, marked_text: &str, cx: &mut ViewContext<Editor>) {
let (umarked_text, text_ranges) = marked_text_ranges(marked_text);
assert_eq!(editor.text(cx), umarked_text);
editor.change_selections(true, cx, |s| s.select_ranges(text_ranges, None));
editor.change_selections(None, cx, |s| s.select_ranges(text_ranges));
}
pub fn assert_text_with_selections(

View File

@ -80,8 +80,8 @@ impl GoToLine {
if let Some(rows) = active_editor.highlighted_rows() {
let snapshot = active_editor.snapshot(cx).display_snapshot;
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
active_editor.change_selections(true, cx, |s| {
s.select_ranges([position..position], Some(Autoscroll::Center))
active_editor.change_selections(Some(Autoscroll::Center), cx, |s| {
s.select_ranges([position..position])
});
}
});

View File

@ -57,8 +57,8 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
if let Some(editor) = item.downcast::<Editor>() {
editor.update(&mut cx, |editor, cx| {
let len = editor.buffer().read(cx).read(cx).len();
editor.change_selections(true, cx, |s| {
s.select_ranges([len..len], Some(Autoscroll::Center))
editor.change_selections(Some(Autoscroll::Center), cx, |s| {
s.select_ranges([len..len])
});
if len > 0 {
editor.insert("\n\n", cx);

View File

@ -215,8 +215,8 @@ impl PickerDelegate for OutlineView {
if let Some(rows) = active_editor.highlighted_rows() {
let snapshot = active_editor.snapshot(cx).display_snapshot;
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
active_editor.change_selections(true, cx, |s| {
s.select_ranges([position..position], Some(Autoscroll::Center))
active_editor.change_selections(Some(Autoscroll::Center), cx, |s| {
s.select_ranges([position..position])
});
}
});

View File

@ -145,8 +145,8 @@ impl ProjectSymbolsView {
let editor = workspace.open_project_item::<Editor>(buffer, cx);
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
s.select_ranges([position..position], Some(Autoscroll::Center))
editor.change_selections(Some(Autoscroll::Center), cx, |s| {
s.select_ranges([position..position])
});
});
});

View File

@ -395,8 +395,8 @@ impl BufferSearchBar {
);
let range_to_select = ranges[new_index].clone();
editor.unfold_ranges([range_to_select.clone()], false, cx);
editor.change_selections(true, cx, |s| {
s.select_ranges([range_to_select], Some(Autoscroll::Fit))
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_ranges([range_to_select])
});
}
});
@ -538,12 +538,11 @@ impl BufferSearchBar {
editor.update(cx, |editor, cx| {
if select_closest_match {
if let Some(match_ix) = this.active_match_index {
editor.change_selections(true, cx, |s| {
s.select_ranges(
[ranges[match_ix].clone()],
editor.change_selections(
Some(Autoscroll::Fit),
)
});
cx,
|s| s.select_ranges([ranges[match_ix].clone()]),
);
}
}
@ -725,7 +724,7 @@ mod tests {
});
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)])
});
});
@ -810,7 +809,7 @@ mod tests {
// Park the cursor in between matches and ensure that going to the previous match selects
// the closest match to the left.
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)])
});
});
@ -829,7 +828,7 @@ mod tests {
// Park the cursor in between matches and ensure that going to the next match selects the
// closest match to the right.
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)])
});
});
@ -848,7 +847,7 @@ mod tests {
// Park the cursor after the last match and ensure that going to the previous match selects
// the last match.
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)])
});
});
@ -867,7 +866,7 @@ mod tests {
// Park the cursor after the last match and ensure that going to the next match selects the
// first match.
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)])
});
});
@ -886,7 +885,7 @@ mod tests {
// Park the cursor before the first match and ensure that going to the previous match
// selects the last match.
editor.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)])
});
});

View File

@ -462,8 +462,8 @@ impl ProjectSearchView {
let range_to_select = model.match_ranges[new_index].clone();
self.results_editor.update(cx, |editor, cx| {
editor.unfold_ranges([range_to_select.clone()], false, cx);
editor.change_selections(true, cx, |s| {
s.select_ranges([range_to_select], Some(Autoscroll::Fit))
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_ranges([range_to_select])
});
});
}
@ -479,9 +479,7 @@ impl ProjectSearchView {
fn focus_results_editor(&self, cx: &mut ViewContext<Self>) {
self.query_editor.update(cx, |query_editor, cx| {
let cursor = query_editor.selections.newest_anchor().head();
query_editor.change_selections(true, cx, |s| {
s.select_ranges([cursor.clone()..cursor], None)
});
query_editor.change_selections(None, cx, |s| s.select_ranges([cursor.clone()..cursor]));
});
cx.focus(&self.results_editor);
}
@ -493,8 +491,8 @@ impl ProjectSearchView {
} else {
self.results_editor.update(cx, |editor, cx| {
if reset_selections {
editor.change_selections(true, cx, |s| {
s.select_ranges(match_ranges.first().cloned(), Some(Autoscroll::Fit))
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_ranges(match_ranges.first().cloned())
});
}
editor.highlight_background::<Self>(

View File

@ -1,5 +1,5 @@
use crate::{state::Mode, Vim};
use editor::Bias;
use editor::{Autoscroll, Bias};
use gpui::{actions, MutableAppContext, ViewContext};
use language::SelectionGoal;
use workspace::Workspace;
@ -13,7 +13,7 @@ pub fn init(cx: &mut MutableAppContext) {
fn normal_before(_: &mut Workspace, _: &NormalBefore, cx: &mut ViewContext<Workspace>) {
Vim::update(cx, |state, cx| {
state.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, mut cursor, _| {
*cursor.column_mut() = cursor.column().saturating_sub(1);
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)

View File

@ -8,7 +8,7 @@ use crate::{
};
use change::init as change_init;
use collections::HashSet;
use editor::{Bias, DisplayPoint};
use editor::{Autoscroll, Bias, DisplayPoint};
use gpui::{actions, MutableAppContext, ViewContext};
use language::SelectionGoal;
use workspace::Workspace;
@ -76,7 +76,7 @@ pub fn normal_motion(motion: Motion, cx: &mut MutableAppContext) {
fn move_cursor(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, cursor, goal| motion.move_point(map, cursor, goal))
})
});
@ -86,7 +86,7 @@ fn insert_after(_: &mut Workspace, _: &InsertAfter, cx: &mut ViewContext<Workspa
Vim::update(cx, |vim, cx| {
vim.switch_mode(Mode::Insert, cx);
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, cursor, goal| {
Motion::Right.move_point(map, cursor, goal)
});
@ -103,7 +103,7 @@ fn insert_first_non_whitespace(
Vim::update(cx, |vim, cx| {
vim.switch_mode(Mode::Insert, cx);
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, cursor, goal| {
Motion::FirstNonWhitespace.move_point(map, cursor, goal)
});
@ -116,7 +116,7 @@ fn insert_end_of_line(_: &mut Workspace, _: &InsertEndOfLine, cx: &mut ViewConte
Vim::update(cx, |vim, cx| {
vim.switch_mode(Mode::Insert, cx);
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, cursor, goal| {
Motion::EndOfLine.move_point(map, cursor, goal)
});
@ -145,7 +145,7 @@ fn insert_line_above(_: &mut Workspace, _: &InsertLineAbove, cx: &mut ViewContex
(start_of_line..start_of_line, new_text)
});
editor.edit_with_autoindent(edits, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, mut cursor, _| {
*cursor.row_mut() -= 1;
*cursor.column_mut() = map.line_len(cursor.row());
@ -176,7 +176,7 @@ fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContex
new_text.push_str(&" ".repeat(indent as usize));
(end_of_line..end_of_line, new_text)
});
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_cursors_with(|map, cursor, goal| {
Motion::EndOfLine.move_point(map, cursor, goal)
});

View File

@ -1,5 +1,5 @@
use crate::{motion::Motion, state::Mode, Vim};
use editor::{char_kind, movement};
use editor::{char_kind, movement, Autoscroll};
use gpui::{impl_actions, MutableAppContext, ViewContext};
use serde::Deserialize;
use workspace::Workspace;
@ -22,7 +22,7 @@ pub fn change_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
editor.transact(cx, |editor, cx| {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
motion.expand_selection(map, selection, false);
});
@ -48,7 +48,7 @@ fn change_word(
editor.transact(cx, |editor, cx| {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
if selection.end.column() == map.line_len(selection.end.row()) {
return;

View File

@ -1,6 +1,6 @@
use crate::{motion::Motion, Vim};
use collections::HashMap;
use editor::Bias;
use editor::{Autoscroll, Bias};
use gpui::MutableAppContext;
pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
@ -8,7 +8,7 @@ pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
editor.transact(cx, |editor, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut original_columns: HashMap<_, _> = Default::default();
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
let original_head = selection.head();
motion.expand_selection(map, selection, true);
@ -19,7 +19,7 @@ pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
// Fixup cursor position after the deletion
editor.set_clip_at_line_ends(true, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
let mut cursor = selection.head();
if motion.linewise() {

View File

@ -3,7 +3,7 @@ use std::ops::{Deref, Range};
use collections::BTreeMap;
use itertools::{Either, Itertools};
use editor::display_map::ToDisplayPoint;
use editor::{display_map::ToDisplayPoint, Autoscroll};
use gpui::{json::json, keymap::Keystroke, ViewHandle};
use indoc::indoc;
use language::Selection;
@ -128,7 +128,7 @@ impl<'a> VimTestContext<'a> {
let (unmarked_text, markers) = marked_text(&text);
editor.set_text(unmarked_text, cx);
let cursor_offset = markers[0];
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.replace_cursors_with(|map| vec![cursor_offset.to_display_point(map)])
});
})

View File

@ -1,4 +1,4 @@
use editor::Bias;
use editor::{Autoscroll, Bias};
use gpui::{actions, MutableAppContext, ViewContext};
use workspace::Workspace;
@ -14,7 +14,7 @@ pub fn init(cx: &mut MutableAppContext) {
pub fn visual_motion(motion: Motion, cx: &mut MutableAppContext) {
Vim::update(cx, |vim, cx| {
vim.update_active_editor(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
let (new_head, goal) = motion.move_point(map, selection.head(), selection.goal);
let new_head = map.clip_at_line_end(new_head);
@ -42,7 +42,7 @@ pub fn change(_: &mut Workspace, _: &VisualChange, cx: &mut ViewContext<Workspac
Vim::update(cx, |vim, cx| {
vim.update_active_editor(cx, |editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
if !selection.reversed {
// Head was at the end of the selection, and now is at the start. We need to move the end
@ -63,7 +63,7 @@ pub fn delete(_: &mut Workspace, _: &VisualDelete, cx: &mut ViewContext<Workspac
vim.switch_mode(Mode::Normal, cx);
vim.update_active_editor(cx, |editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
if !selection.reversed {
// Head was at the end of the selection, and now is at the start. We need to move the end
@ -77,7 +77,7 @@ pub fn delete(_: &mut Workspace, _: &VisualDelete, cx: &mut ViewContext<Workspac
// Fixup cursor position after the deletion
editor.set_clip_at_line_ends(true, cx);
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
let mut cursor = selection.head();
cursor = map.clip_point(cursor, Bias::Left);

View File

@ -309,7 +309,7 @@ fn open_config_file(
mod tests {
use super::*;
use assets::Assets;
use editor::{DisplayPoint, Editor};
use editor::{Autoscroll, DisplayPoint, Editor};
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
use project::{Fs, ProjectPath};
use serde_json::json;
@ -962,7 +962,7 @@ mod tests {
.downcast::<Editor>()
.unwrap();
editor1.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_display_ranges([DisplayPoint::new(10, 0)..DisplayPoint::new(10, 0)])
});
});
@ -981,7 +981,7 @@ mod tests {
editor3
.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.select_display_ranges([DisplayPoint::new(12, 0)..DisplayPoint::new(12, 0)])
});
editor.newline(&Default::default(), cx);
@ -1124,19 +1124,19 @@ mod tests {
// Modify file to collapse multiple nav history entries into the same location.
// Ensure we don't visit the same location twice when navigating.
editor1.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)])
})
});
for _ in 0..5 {
editor1.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)])
});
});
editor1.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(13, 0)..DisplayPoint::new(13, 0)])
})
});
@ -1144,7 +1144,7 @@ mod tests {
editor1.update(cx, |editor, cx| {
editor.transact(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(2, 0)..DisplayPoint::new(14, 0)])
});
editor.insert("", cx);
@ -1152,7 +1152,7 @@ mod tests {
});
editor1.update(cx, |editor, cx| {
editor.change_selections(true, cx, |s| {
editor.change_selections(None, cx, |s| {
s.select_display_ranges([DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)])
})
});