mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 21:26:14 +03:00
Passing tests and removed local argument. Also pulled autoscroll argument out to change_selections
This commit is contained in:
parent
c9dcfff607
commit
db0a9114c2
@ -3001,7 +3001,7 @@ mod tests {
|
|||||||
|
|
||||||
// Type a completion trigger character as the guest.
|
// Type a completion trigger character as the guest.
|
||||||
editor_b.update(cx_b, |editor, cx| {
|
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);
|
editor.handle_input(&Input(".".into()), cx);
|
||||||
cx.focus(&editor_b);
|
cx.focus(&editor_b);
|
||||||
});
|
});
|
||||||
@ -4213,8 +4213,8 @@ mod tests {
|
|||||||
|
|
||||||
// Move cursor to a location that contains code actions.
|
// Move cursor to a location that contains code actions.
|
||||||
editor_b.update(cx_b, |editor, cx| {
|
editor_b.update(cx_b, |editor, cx| {
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(None, cx, |s| {
|
||||||
s.select_ranges([Point::new(1, 31)..Point::new(1, 31)], None)
|
s.select_ranges([Point::new(1, 31)..Point::new(1, 31)])
|
||||||
});
|
});
|
||||||
cx.focus(&editor_b);
|
cx.focus(&editor_b);
|
||||||
});
|
});
|
||||||
@ -4452,7 +4452,7 @@ mod tests {
|
|||||||
|
|
||||||
// Move cursor to a location that can be renamed.
|
// Move cursor to a location that can be renamed.
|
||||||
let prepare_rename = editor_b.update(cx_b, |editor, cx| {
|
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()
|
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.
|
// When client B starts following client A, all visible view states are replicated to client B.
|
||||||
editor_a1.update(cx_a, |editor, cx| {
|
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_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
|
workspace_b
|
||||||
.update(cx_b, |workspace, cx| {
|
.update(cx_b, |workspace, cx| {
|
||||||
@ -5542,7 +5542,7 @@ mod tests {
|
|||||||
|
|
||||||
// Changes to client A's editor are reflected on client B.
|
// Changes to client A's editor are reflected on client B.
|
||||||
editor_a1.update(cx_a, |editor, cx| {
|
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
|
editor_b1
|
||||||
.condition(cx_b, |editor, cx| {
|
.condition(cx_b, |editor, cx| {
|
||||||
@ -5556,7 +5556,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
editor_a1.update(cx_a, |editor, cx| {
|
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.set_scroll_position(vec2f(0., 100.), cx);
|
||||||
});
|
});
|
||||||
editor_b1
|
editor_b1
|
||||||
|
@ -5,7 +5,7 @@ use collections::{BTreeSet, HashSet};
|
|||||||
use editor::{
|
use editor::{
|
||||||
diagnostic_block_renderer,
|
diagnostic_block_renderer,
|
||||||
display_map::{BlockDisposition, BlockId, BlockProperties, RenderBlock},
|
display_map::{BlockDisposition, BlockId, BlockProperties, RenderBlock},
|
||||||
highlight_diagnostic_message, Editor, ExcerptId, MultiBuffer, ToOffset,
|
highlight_diagnostic_message, Autoscroll, Editor, ExcerptId, MultiBuffer, ToOffset,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::*, fonts::TextStyle, serde_json, AnyViewHandle, AppContext, Entity,
|
actions, elements::*, fonts::TextStyle, serde_json, AnyViewHandle, AppContext, Entity,
|
||||||
@ -418,7 +418,7 @@ impl ProjectDiagnosticsEditor {
|
|||||||
} else {
|
} else {
|
||||||
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(true, cx, |s| s.refresh());
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| s.refresh());
|
||||||
selections = editor
|
selections = editor
|
||||||
.selections
|
.selections
|
||||||
.interleaved::<usize>(&editor.buffer().read(cx).read(cx));
|
.interleaved::<usize>(&editor.buffer().read(cx).read(cx));
|
||||||
@ -444,8 +444,8 @@ impl ProjectDiagnosticsEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(None, cx, |s| {
|
||||||
s.select(selections, None);
|
s.select(selections);
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
});
|
});
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -276,8 +276,8 @@ impl Item for Editor {
|
|||||||
let nav_history = self.nav_history.take();
|
let nav_history = self.nav_history.take();
|
||||||
self.scroll_position = data.scroll_position;
|
self.scroll_position = data.scroll_position;
|
||||||
self.scroll_top_anchor = scroll_top_anchor;
|
self.scroll_top_anchor = scroll_top_anchor;
|
||||||
self.change_selections(true, cx, |s| {
|
self.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||||
s.select_ranges([offset..offset], Some(Autoscroll::Fit))
|
s.select_ranges([offset..offset])
|
||||||
});
|
});
|
||||||
self.nav_history = nav_history;
|
self.nav_history = nav_history;
|
||||||
true
|
true
|
||||||
|
@ -12,8 +12,7 @@ use util::post_inc;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
|
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
|
||||||
Anchor, Autoscroll, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode,
|
Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset,
|
||||||
ToOffset,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -79,10 +78,10 @@ impl SelectionsCollection {
|
|||||||
|
|
||||||
pub fn interleaved<'a, D>(&self, buffer: &MultiBufferSnapshot) -> Vec<Selection<D>>
|
pub fn interleaved<'a, D>(&self, buffer: &MultiBufferSnapshot) -> Vec<Selection<D>>
|
||||||
where
|
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 disjoint_anchors = &self.disjoint;
|
||||||
let mut disjoint = resolve_multiple::<D, _>(anchor_disjoint.iter(), &buffer).peekable();
|
let mut disjoint = resolve_multiple::<D, _>(disjoint_anchors.iter(), &buffer).peekable();
|
||||||
|
|
||||||
let mut pending_opt = self.pending::<D>(&buffer);
|
let mut pending_opt = self.pending::<D>(&buffer);
|
||||||
|
|
||||||
@ -197,36 +196,31 @@ impl SelectionsCollection {
|
|||||||
self.interleaved(&snapshot).last().unwrap().clone()
|
self.interleaved(&snapshot).last().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE do not use. This should only be called from Editor::change_selections.
|
pub(crate) fn change_with<R>(
|
||||||
#[deprecated]
|
|
||||||
pub fn change_with<R>(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
display_map: ModelHandle<DisplayMap>,
|
display_map: ModelHandle<DisplayMap>,
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
|
change: impl FnOnce(&mut MutableSelectionsCollection) -> R,
|
||||||
) -> (Option<Autoscroll>, R) {
|
) -> R {
|
||||||
let mut mutable_collection = MutableSelectionsCollection {
|
let mut mutable_collection = MutableSelectionsCollection {
|
||||||
collection: self,
|
collection: self,
|
||||||
autoscroll: None,
|
|
||||||
display_map,
|
display_map,
|
||||||
buffer,
|
buffer,
|
||||||
cx,
|
cx,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = change(&mut mutable_collection);
|
let result = change(&mut mutable_collection);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!mutable_collection.disjoint.is_empty() || mutable_collection.pending.is_some(),
|
!mutable_collection.disjoint.is_empty() || mutable_collection.pending.is_some(),
|
||||||
"There must be at least one selection"
|
"There must be at least one selection"
|
||||||
);
|
);
|
||||||
(mutable_collection.autoscroll, result)
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MutableSelectionsCollection<'a> {
|
pub struct MutableSelectionsCollection<'a> {
|
||||||
collection: &'a mut SelectionsCollection,
|
collection: &'a mut SelectionsCollection,
|
||||||
pub autoscroll: Option<Autoscroll>,
|
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
display_map: ModelHandle<DisplayMap>,
|
display_map: ModelHandle<DisplayMap>,
|
||||||
cx: &'a mut MutableAppContext,
|
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
|
where
|
||||||
T: 'a
|
T: 'a
|
||||||
+ ToOffset
|
+ ToOffset
|
||||||
@ -335,10 +329,10 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
reversed,
|
reversed,
|
||||||
goal: SelectionGoal::None,
|
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
|
where
|
||||||
T: ToOffset + ToPoint + Ord + std::marker::Copy + std::fmt::Debug,
|
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| {
|
self.collection.disjoint = Arc::from_iter(selections.into_iter().map(|selection| {
|
||||||
let end_bias = if selection.end > selection.start {
|
let end_bias = if selection.end > selection.start {
|
||||||
Bias::Left
|
Bias::Left
|
||||||
@ -380,46 +372,14 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
self.collection.pending = None;
|
self.collection.pending = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_anchors(
|
pub fn select_anchors(&mut self, selections: Vec<Selection<Anchor>>) {
|
||||||
&mut self,
|
|
||||||
mut selections: Vec<Selection<Anchor>>,
|
|
||||||
autoscroll: Option<Autoscroll>,
|
|
||||||
) {
|
|
||||||
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
||||||
selections.sort_unstable_by(|a, b| a.start.cmp(&b.start, &buffer));
|
let resolved_selections =
|
||||||
|
resolve_multiple::<usize, _>(&selections, &buffer).collect::<Vec<_>>();
|
||||||
// Merge overlapping selections.
|
self.select(resolved_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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.autoscroll = autoscroll.or(self.autoscroll.take());
|
pub fn select_ranges<I, T>(&mut self, ranges: I)
|
||||||
|
|
||||||
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>)
|
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = Range<T>>,
|
I: IntoIterator<Item = Range<T>>,
|
||||||
T: ToOffset,
|
T: ToOffset,
|
||||||
@ -446,14 +406,10 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.select(selections, autoscroll)
|
self.select(selections)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_anchor_ranges<I: IntoIterator<Item = Range<Anchor>>>(
|
pub fn select_anchor_ranges<I: IntoIterator<Item = Range<Anchor>>>(&mut self, ranges: I) {
|
||||||
&mut self,
|
|
||||||
ranges: I,
|
|
||||||
autoscroll: Option<Autoscroll>,
|
|
||||||
) {
|
|
||||||
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
||||||
let selections = ranges
|
let selections = ranges
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -476,7 +432,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.select_anchors(selections, autoscroll)
|
self.select_anchors(selections)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
@ -505,7 +461,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.select(selections, None);
|
self.select(selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_with(
|
pub fn move_with(
|
||||||
@ -523,7 +479,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.select(selections, Some(Autoscroll::Fit))
|
self.select(selections)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_heads_with(
|
pub fn move_heads_with(
|
||||||
@ -572,7 +528,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.select(new_selections, None);
|
self.select(new_selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute new ranges for any selections that were located in excerpts that have
|
/// Compute new ranges for any selections that were located in excerpts that have
|
||||||
@ -620,10 +576,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !adjusted_disjoint.is_empty() {
|
if !adjusted_disjoint.is_empty() {
|
||||||
self.select::<usize>(
|
self.select::<usize>(resolve_multiple(adjusted_disjoint.iter(), &buffer).collect());
|
||||||
resolve_multiple(adjusted_disjoint.iter(), &buffer).collect(),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(pending) = pending.as_mut() {
|
if let Some(pending) = pending.as_mut() {
|
||||||
@ -665,12 +618,16 @@ pub fn resolve_multiple<'a, D, I>(
|
|||||||
snapshot: &MultiBufferSnapshot,
|
snapshot: &MultiBufferSnapshot,
|
||||||
) -> impl 'a + Iterator<Item = Selection<D>>
|
) -> impl 'a + Iterator<Item = Selection<D>>
|
||||||
where
|
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>>,
|
I: 'a + IntoIterator<Item = &'a Selection<Anchor>>,
|
||||||
{
|
{
|
||||||
let (to_summarize, selections) = selections.into_iter().tee();
|
let (to_summarize, selections) = selections.into_iter().tee();
|
||||||
let mut summaries = snapshot
|
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();
|
.into_iter();
|
||||||
selections.map(move |s| Selection {
|
selections.map(move |s| Selection {
|
||||||
id: s.id,
|
id: s.id,
|
||||||
@ -692,7 +649,7 @@ fn reset_biases(
|
|||||||
mut selection: Selection<Anchor>,
|
mut selection: Selection<Anchor>,
|
||||||
buffer: &MultiBufferSnapshot,
|
buffer: &MultiBufferSnapshot,
|
||||||
) -> Selection<Anchor> {
|
) -> 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
|
Bias::Left
|
||||||
} else {
|
} else {
|
||||||
Bias::Right
|
Bias::Right
|
||||||
|
@ -43,7 +43,7 @@ pub fn marked_display_snapshot(
|
|||||||
pub fn select_ranges(editor: &mut Editor, marked_text: &str, cx: &mut ViewContext<Editor>) {
|
pub fn select_ranges(editor: &mut Editor, marked_text: &str, cx: &mut ViewContext<Editor>) {
|
||||||
let (umarked_text, text_ranges) = marked_text_ranges(marked_text);
|
let (umarked_text, text_ranges) = marked_text_ranges(marked_text);
|
||||||
assert_eq!(editor.text(cx), umarked_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(
|
pub fn assert_text_with_selections(
|
||||||
|
@ -80,8 +80,8 @@ impl GoToLine {
|
|||||||
if let Some(rows) = active_editor.highlighted_rows() {
|
if let Some(rows) = active_editor.highlighted_rows() {
|
||||||
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
||||||
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
|
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
|
||||||
active_editor.change_selections(true, cx, |s| {
|
active_editor.change_selections(Some(Autoscroll::Center), cx, |s| {
|
||||||
s.select_ranges([position..position], Some(Autoscroll::Center))
|
s.select_ranges([position..position])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -57,8 +57,8 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
|||||||
if let Some(editor) = item.downcast::<Editor>() {
|
if let Some(editor) = item.downcast::<Editor>() {
|
||||||
editor.update(&mut cx, |editor, cx| {
|
editor.update(&mut cx, |editor, cx| {
|
||||||
let len = editor.buffer().read(cx).read(cx).len();
|
let len = editor.buffer().read(cx).read(cx).len();
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(Some(Autoscroll::Center), cx, |s| {
|
||||||
s.select_ranges([len..len], Some(Autoscroll::Center))
|
s.select_ranges([len..len])
|
||||||
});
|
});
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
editor.insert("\n\n", cx);
|
editor.insert("\n\n", cx);
|
||||||
|
@ -215,8 +215,8 @@ impl PickerDelegate for OutlineView {
|
|||||||
if let Some(rows) = active_editor.highlighted_rows() {
|
if let Some(rows) = active_editor.highlighted_rows() {
|
||||||
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
||||||
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
|
let position = DisplayPoint::new(rows.start, 0).to_point(&snapshot);
|
||||||
active_editor.change_selections(true, cx, |s| {
|
active_editor.change_selections(Some(Autoscroll::Center), cx, |s| {
|
||||||
s.select_ranges([position..position], Some(Autoscroll::Center))
|
s.select_ranges([position..position])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -145,8 +145,8 @@ impl ProjectSymbolsView {
|
|||||||
|
|
||||||
let editor = workspace.open_project_item::<Editor>(buffer, cx);
|
let editor = workspace.open_project_item::<Editor>(buffer, cx);
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(Some(Autoscroll::Center), cx, |s| {
|
||||||
s.select_ranges([position..position], Some(Autoscroll::Center))
|
s.select_ranges([position..position])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -395,8 +395,8 @@ impl BufferSearchBar {
|
|||||||
);
|
);
|
||||||
let range_to_select = ranges[new_index].clone();
|
let range_to_select = ranges[new_index].clone();
|
||||||
editor.unfold_ranges([range_to_select.clone()], false, cx);
|
editor.unfold_ranges([range_to_select.clone()], false, cx);
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||||
s.select_ranges([range_to_select], Some(Autoscroll::Fit))
|
s.select_ranges([range_to_select])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -538,12 +538,11 @@ impl BufferSearchBar {
|
|||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
if select_closest_match {
|
if select_closest_match {
|
||||||
if let Some(match_ix) = this.active_match_index {
|
if let Some(match_ix) = this.active_match_index {
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(
|
||||||
s.select_ranges(
|
|
||||||
[ranges[match_ix].clone()],
|
|
||||||
Some(Autoscroll::Fit),
|
Some(Autoscroll::Fit),
|
||||||
)
|
cx,
|
||||||
});
|
|s| s.select_ranges([ranges[match_ix].clone()]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,7 +724,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
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
|
// Park the cursor in between matches and ensure that going to the previous match selects
|
||||||
// the closest match to the left.
|
// the closest match to the left.
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
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
|
// Park the cursor in between matches and ensure that going to the next match selects the
|
||||||
// closest match to the right.
|
// closest match to the right.
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
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
|
// Park the cursor after the last match and ensure that going to the previous match selects
|
||||||
// the last match.
|
// the last match.
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
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
|
// Park the cursor after the last match and ensure that going to the next match selects the
|
||||||
// first match.
|
// first match.
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
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
|
// Park the cursor before the first match and ensure that going to the previous match
|
||||||
// selects the last match.
|
// selects the last match.
|
||||||
editor.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -462,8 +462,8 @@ impl ProjectSearchView {
|
|||||||
let range_to_select = model.match_ranges[new_index].clone();
|
let range_to_select = model.match_ranges[new_index].clone();
|
||||||
self.results_editor.update(cx, |editor, cx| {
|
self.results_editor.update(cx, |editor, cx| {
|
||||||
editor.unfold_ranges([range_to_select.clone()], false, cx);
|
editor.unfold_ranges([range_to_select.clone()], false, cx);
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||||
s.select_ranges([range_to_select], Some(Autoscroll::Fit))
|
s.select_ranges([range_to_select])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -479,9 +479,7 @@ impl ProjectSearchView {
|
|||||||
fn focus_results_editor(&self, cx: &mut ViewContext<Self>) {
|
fn focus_results_editor(&self, cx: &mut ViewContext<Self>) {
|
||||||
self.query_editor.update(cx, |query_editor, cx| {
|
self.query_editor.update(cx, |query_editor, cx| {
|
||||||
let cursor = query_editor.selections.newest_anchor().head();
|
let cursor = query_editor.selections.newest_anchor().head();
|
||||||
query_editor.change_selections(true, cx, |s| {
|
query_editor.change_selections(None, cx, |s| s.select_ranges([cursor.clone()..cursor]));
|
||||||
s.select_ranges([cursor.clone()..cursor], None)
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
cx.focus(&self.results_editor);
|
cx.focus(&self.results_editor);
|
||||||
}
|
}
|
||||||
@ -493,8 +491,8 @@ impl ProjectSearchView {
|
|||||||
} else {
|
} else {
|
||||||
self.results_editor.update(cx, |editor, cx| {
|
self.results_editor.update(cx, |editor, cx| {
|
||||||
if reset_selections {
|
if reset_selections {
|
||||||
editor.change_selections(true, cx, |s| {
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||||
s.select_ranges(match_ranges.first().cloned(), Some(Autoscroll::Fit))
|
s.select_ranges(match_ranges.first().cloned())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
editor.highlight_background::<Self>(
|
editor.highlight_background::<Self>(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{state::Mode, Vim};
|
use crate::{state::Mode, Vim};
|
||||||
use editor::Bias;
|
use editor::{Autoscroll, Bias};
|
||||||
use gpui::{actions, MutableAppContext, ViewContext};
|
use gpui::{actions, MutableAppContext, ViewContext};
|
||||||
use language::SelectionGoal;
|
use language::SelectionGoal;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
@ -13,7 +13,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||||||
fn normal_before(_: &mut Workspace, _: &NormalBefore, cx: &mut ViewContext<Workspace>) {
|
fn normal_before(_: &mut Workspace, _: &NormalBefore, cx: &mut ViewContext<Workspace>) {
|
||||||
Vim::update(cx, |state, cx| {
|
Vim::update(cx, |state, cx| {
|
||||||
state.update_active_editor(cx, |editor, 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, _| {
|
s.move_cursors_with(|map, mut cursor, _| {
|
||||||
*cursor.column_mut() = cursor.column().saturating_sub(1);
|
*cursor.column_mut() = cursor.column().saturating_sub(1);
|
||||||
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)
|
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)
|
||||||
|
@ -8,7 +8,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use change::init as change_init;
|
use change::init as change_init;
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use editor::{Bias, DisplayPoint};
|
use editor::{Autoscroll, Bias, DisplayPoint};
|
||||||
use gpui::{actions, MutableAppContext, ViewContext};
|
use gpui::{actions, MutableAppContext, ViewContext};
|
||||||
use language::SelectionGoal;
|
use language::SelectionGoal;
|
||||||
use workspace::Workspace;
|
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) {
|
fn move_cursor(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
||||||
vim.update_active_editor(cx, |editor, 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.move_point(map, cursor, goal))
|
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::update(cx, |vim, cx| {
|
||||||
vim.switch_mode(Mode::Insert, cx);
|
vim.switch_mode(Mode::Insert, cx);
|
||||||
vim.update_active_editor(cx, |editor, 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| {
|
s.move_cursors_with(|map, cursor, goal| {
|
||||||
Motion::Right.move_point(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::update(cx, |vim, cx| {
|
||||||
vim.switch_mode(Mode::Insert, cx);
|
vim.switch_mode(Mode::Insert, cx);
|
||||||
vim.update_active_editor(cx, |editor, 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| {
|
s.move_cursors_with(|map, cursor, goal| {
|
||||||
Motion::FirstNonWhitespace.move_point(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::update(cx, |vim, cx| {
|
||||||
vim.switch_mode(Mode::Insert, cx);
|
vim.switch_mode(Mode::Insert, cx);
|
||||||
vim.update_active_editor(cx, |editor, 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| {
|
s.move_cursors_with(|map, cursor, goal| {
|
||||||
Motion::EndOfLine.move_point(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)
|
(start_of_line..start_of_line, new_text)
|
||||||
});
|
});
|
||||||
editor.edit_with_autoindent(edits, cx);
|
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, _| {
|
s.move_cursors_with(|map, mut cursor, _| {
|
||||||
*cursor.row_mut() -= 1;
|
*cursor.row_mut() -= 1;
|
||||||
*cursor.column_mut() = map.line_len(cursor.row());
|
*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));
|
new_text.push_str(&" ".repeat(indent as usize));
|
||||||
(end_of_line..end_of_line, new_text)
|
(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| {
|
s.move_cursors_with(|map, cursor, goal| {
|
||||||
Motion::EndOfLine.move_point(map, cursor, goal)
|
Motion::EndOfLine.move_point(map, cursor, goal)
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{motion::Motion, state::Mode, Vim};
|
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 gpui::{impl_actions, MutableAppContext, ViewContext};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
@ -22,7 +22,7 @@ pub fn change_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||||
editor.set_clip_at_line_ends(false, 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| {
|
s.move_with(|map, selection| {
|
||||||
motion.expand_selection(map, selection, false);
|
motion.expand_selection(map, selection, false);
|
||||||
});
|
});
|
||||||
@ -48,7 +48,7 @@ fn change_word(
|
|||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||||
editor.set_clip_at_line_ends(false, 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| {
|
s.move_with(|map, selection| {
|
||||||
if selection.end.column() == map.line_len(selection.end.row()) {
|
if selection.end.column() == map.line_len(selection.end.row()) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{motion::Motion, Vim};
|
use crate::{motion::Motion, Vim};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use editor::Bias;
|
use editor::{Autoscroll, Bias};
|
||||||
use gpui::MutableAppContext;
|
use gpui::MutableAppContext;
|
||||||
|
|
||||||
pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut 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.transact(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
let mut original_columns: HashMap<_, _> = Default::default();
|
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| {
|
s.move_with(|map, selection| {
|
||||||
let original_head = selection.head();
|
let original_head = selection.head();
|
||||||
motion.expand_selection(map, selection, true);
|
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
|
// Fixup cursor position after the deletion
|
||||||
editor.set_clip_at_line_ends(true, cx);
|
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| {
|
s.move_with(|map, selection| {
|
||||||
let mut cursor = selection.head();
|
let mut cursor = selection.head();
|
||||||
if motion.linewise() {
|
if motion.linewise() {
|
||||||
|
@ -3,7 +3,7 @@ use std::ops::{Deref, Range};
|
|||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use itertools::{Either, Itertools};
|
use itertools::{Either, Itertools};
|
||||||
|
|
||||||
use editor::display_map::ToDisplayPoint;
|
use editor::{display_map::ToDisplayPoint, Autoscroll};
|
||||||
use gpui::{json::json, keymap::Keystroke, ViewHandle};
|
use gpui::{json::json, keymap::Keystroke, ViewHandle};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use language::Selection;
|
use language::Selection;
|
||||||
@ -128,7 +128,7 @@ impl<'a> VimTestContext<'a> {
|
|||||||
let (unmarked_text, markers) = marked_text(&text);
|
let (unmarked_text, markers) = marked_text(&text);
|
||||||
editor.set_text(unmarked_text, cx);
|
editor.set_text(unmarked_text, cx);
|
||||||
let cursor_offset = markers[0];
|
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)])
|
s.replace_cursors_with(|map| vec![cursor_offset.to_display_point(map)])
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use editor::Bias;
|
use editor::{Autoscroll, Bias};
|
||||||
use gpui::{actions, MutableAppContext, ViewContext};
|
use gpui::{actions, MutableAppContext, ViewContext};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||||||
pub fn visual_motion(motion: Motion, cx: &mut MutableAppContext) {
|
pub fn visual_motion(motion: Motion, cx: &mut MutableAppContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |editor, 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| {
|
s.move_with(|map, selection| {
|
||||||
let (new_head, goal) = motion.move_point(map, selection.head(), selection.goal);
|
let (new_head, goal) = motion.move_point(map, selection.head(), selection.goal);
|
||||||
let new_head = map.clip_at_line_end(new_head);
|
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(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, 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| {
|
s.move_with(|map, selection| {
|
||||||
if !selection.reversed {
|
if !selection.reversed {
|
||||||
// Head was at the end of the selection, and now is at the start. We need to move the end
|
// 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.switch_mode(Mode::Normal, cx);
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, 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| {
|
s.move_with(|map, selection| {
|
||||||
if !selection.reversed {
|
if !selection.reversed {
|
||||||
// Head was at the end of the selection, and now is at the start. We need to move the end
|
// 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
|
// Fixup cursor position after the deletion
|
||||||
editor.set_clip_at_line_ends(true, cx);
|
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| {
|
s.move_with(|map, selection| {
|
||||||
let mut cursor = selection.head();
|
let mut cursor = selection.head();
|
||||||
cursor = map.clip_point(cursor, Bias::Left);
|
cursor = map.clip_point(cursor, Bias::Left);
|
||||||
|
@ -309,7 +309,7 @@ fn open_config_file(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use editor::{DisplayPoint, Editor};
|
use editor::{Autoscroll, DisplayPoint, Editor};
|
||||||
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
|
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
|
||||||
use project::{Fs, ProjectPath};
|
use project::{Fs, ProjectPath};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -962,7 +962,7 @@ mod tests {
|
|||||||
.downcast::<Editor>()
|
.downcast::<Editor>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
editor1.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(10, 0)..DisplayPoint::new(10, 0)])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -981,7 +981,7 @@ mod tests {
|
|||||||
|
|
||||||
editor3
|
editor3
|
||||||
.update(cx, |editor, cx| {
|
.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)])
|
s.select_display_ranges([DisplayPoint::new(12, 0)..DisplayPoint::new(12, 0)])
|
||||||
});
|
});
|
||||||
editor.newline(&Default::default(), cx);
|
editor.newline(&Default::default(), cx);
|
||||||
@ -1124,19 +1124,19 @@ mod tests {
|
|||||||
// Modify file to collapse multiple nav history entries into the same location.
|
// Modify file to collapse multiple nav history entries into the same location.
|
||||||
// Ensure we don't visit the same location twice when navigating.
|
// Ensure we don't visit the same location twice when navigating.
|
||||||
editor1.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)])
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
editor1.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
editor1.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(13, 0)..DisplayPoint::new(13, 0)])
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -1144,7 +1144,7 @@ mod tests {
|
|||||||
|
|
||||||
editor1.update(cx, |editor, cx| {
|
editor1.update(cx, |editor, cx| {
|
||||||
editor.transact(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)])
|
s.select_display_ranges([DisplayPoint::new(2, 0)..DisplayPoint::new(14, 0)])
|
||||||
});
|
});
|
||||||
editor.insert("", cx);
|
editor.insert("", cx);
|
||||||
@ -1152,7 +1152,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
editor1.update(cx, |editor, cx| {
|
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)])
|
s.select_display_ranges([DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)])
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user