Remove into SelectionEffects
from .change_selections (#33554)
In #32656 I generalized the argument to change selections to allow controling both the scroll and the nav history (and the completion trigger). To avoid conflicting with ongoing debugger cherry-picks I left the argument as an `impl Into<>`, but I think it's clearer to make callers specify what they want here. I converted a lot of `None` arguments to `SelectionEffects::no_scroll()` to be exactly compatible; but I think many people used none as an "i don't care" value in which case Default::default() might be more appropraite Closes #ISSUE Release Notes: - N/A
This commit is contained in:
parent
6e762d9c05
commit
a675ca7a1e
65 changed files with 837 additions and 625 deletions
|
@ -1,4 +1,4 @@
|
|||
use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement, scroll::Autoscroll};
|
||||
use editor::{Bias, Direction, Editor, display_map::ToDisplayPoint, movement};
|
||||
use gpui::{Context, Window, actions};
|
||||
|
||||
use crate::{Vim, state::Mode};
|
||||
|
@ -29,7 +29,7 @@ impl Vim {
|
|||
.next_change(count, direction)
|
||||
.map(|s| s.to_vec())
|
||||
{
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let map = s.display_map();
|
||||
s.select_display_ranges(selections.iter().map(|a| {
|
||||
let point = a.to_display_point(&map);
|
||||
|
|
|
@ -2,10 +2,9 @@ use anyhow::Result;
|
|||
use collections::{HashMap, HashSet};
|
||||
use command_palette_hooks::CommandInterceptResult;
|
||||
use editor::{
|
||||
Bias, Editor, ToPoint,
|
||||
Bias, Editor, SelectionEffects, ToPoint,
|
||||
actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive},
|
||||
display_map::ToDisplayPoint,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Action, App, AppContext as _, Context, Global, Window, actions};
|
||||
use itertools::Itertools;
|
||||
|
@ -422,7 +421,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
let target = snapshot
|
||||
.buffer_snapshot
|
||||
.clip_point(Point::new(buffer_row.0, current.head().column), Bias::Left);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges([target..target]);
|
||||
});
|
||||
|
||||
|
@ -493,7 +492,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
.disjoint_anchor_ranges()
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
let end = Point::new(range.end.0, s.buffer().line_len(range.end));
|
||||
s.select_ranges([end..Point::new(range.start.0, 0)]);
|
||||
});
|
||||
|
@ -503,7 +502,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
window.dispatch_action(action.action.boxed_clone(), cx);
|
||||
cx.defer_in(window, move |vim, window, cx| {
|
||||
vim.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
if let Some(previous_selections) = previous_selections {
|
||||
s.select_ranges(previous_selections);
|
||||
} else {
|
||||
|
@ -1455,15 +1454,20 @@ impl OnMatchingLines {
|
|||
editor
|
||||
.update_in(cx, |editor, window, cx| {
|
||||
editor.start_transaction_at(Instant::now(), window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.replace_cursors_with(|_| new_selections);
|
||||
});
|
||||
window.dispatch_action(action, cx);
|
||||
cx.defer_in(window, move |editor, window, cx| {
|
||||
let newest = editor.selections.newest::<Point>(cx).clone();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
s.select(vec![newest]);
|
||||
});
|
||||
editor.change_selections(
|
||||
SelectionEffects::no_scroll(),
|
||||
window,
|
||||
cx,
|
||||
|s| {
|
||||
s.select(vec![newest]);
|
||||
},
|
||||
);
|
||||
editor.end_transaction_at(Instant::now(), cx);
|
||||
})
|
||||
})
|
||||
|
@ -1566,7 +1570,7 @@ impl Vim {
|
|||
)
|
||||
.unwrap_or((start.range(), MotionKind::Exclusive));
|
||||
if range.start != start.start {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges([
|
||||
range.start.to_point(&snapshot)..range.start.to_point(&snapshot)
|
||||
]);
|
||||
|
@ -1606,7 +1610,7 @@ impl Vim {
|
|||
.range(&snapshot, start.clone(), around)
|
||||
.unwrap_or(start.range());
|
||||
if range.start != start.start {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges([
|
||||
range.start.to_point(&snapshot)..range.start.to_point(&snapshot)
|
||||
]);
|
||||
|
@ -1799,7 +1803,7 @@ impl ShellExec {
|
|||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.edit([(range.clone(), text)], cx);
|
||||
let snapshot = editor.buffer().read(cx).snapshot(cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let point = if is_read {
|
||||
let point = range.end.to_point(&snapshot);
|
||||
Point::new(point.row.saturating_sub(1), 0)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{DisplayPoint, Editor, movement, scroll::Autoscroll};
|
||||
use editor::{DisplayPoint, Editor, movement};
|
||||
use gpui::{Action, actions};
|
||||
use gpui::{Context, Window};
|
||||
use language::{CharClassifier, CharKind};
|
||||
|
@ -47,7 +47,7 @@ impl Vim {
|
|||
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
|
||||
) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let times = times.unwrap_or(1);
|
||||
let new_goal = SelectionGoal::None;
|
||||
|
@ -100,7 +100,7 @@ impl Vim {
|
|||
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
|
||||
) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let times = times.unwrap_or(1);
|
||||
let new_goal = SelectionGoal::None;
|
||||
|
@ -161,7 +161,7 @@ impl Vim {
|
|||
) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let goal = selection.goal;
|
||||
let cursor = if selection.is_empty() || selection.reversed {
|
||||
|
@ -239,7 +239,7 @@ impl Vim {
|
|||
Motion::FindForward { .. } => {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let goal = selection.goal;
|
||||
let cursor = if selection.is_empty() || selection.reversed {
|
||||
|
@ -266,7 +266,7 @@ impl Vim {
|
|||
Motion::FindBackward { .. } => {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let goal = selection.goal;
|
||||
let cursor = if selection.is_empty() || selection.reversed {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{Vim, motion::Motion, object::Object, state::Mode};
|
||||
use collections::HashMap;
|
||||
use editor::SelectionEffects;
|
||||
use editor::{Bias, Editor, display_map::ToDisplayPoint};
|
||||
use gpui::actions;
|
||||
use gpui::{Context, Window};
|
||||
|
@ -88,7 +89,7 @@ impl Vim {
|
|||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut selection_starts: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
selection_starts.insert(selection.id, anchor);
|
||||
|
@ -106,7 +107,7 @@ impl Vim {
|
|||
IndentDirection::Out => editor.outdent(&Default::default(), window, cx),
|
||||
IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx),
|
||||
}
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = selection_starts.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
@ -128,7 +129,7 @@ impl Vim {
|
|||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut original_positions: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
original_positions.insert(selection.id, anchor);
|
||||
|
@ -140,7 +141,7 @@ impl Vim {
|
|||
IndentDirection::Out => editor.outdent(&Default::default(), window, cx),
|
||||
IndentDirection::Auto => editor.autoindent(&Default::default(), window, cx),
|
||||
}
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = original_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{Vim, state::Mode};
|
||||
use editor::{Bias, Editor, scroll::Autoscroll};
|
||||
use editor::{Bias, Editor};
|
||||
use gpui::{Action, Context, Window, actions};
|
||||
use language::SelectionGoal;
|
||||
use settings::Settings;
|
||||
|
@ -34,7 +34,7 @@ impl Vim {
|
|||
editor.dismiss_menus_and_popups(false, window, cx);
|
||||
|
||||
if !HelixModeSetting::get_global(cx).0 {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, 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)
|
||||
|
|
|
@ -4,7 +4,6 @@ use editor::{
|
|||
movement::{
|
||||
self, FindRange, TextLayoutDetails, find_boundary, find_preceding_boundary_display_point,
|
||||
},
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Action, Context, Window, actions, px};
|
||||
use language::{CharKind, Point, Selection, SelectionGoal};
|
||||
|
@ -626,7 +625,7 @@ impl Vim {
|
|||
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
|
||||
if !prior_selections.is_empty() {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(prior_selections.iter().cloned())
|
||||
})
|
||||
});
|
||||
|
|
|
@ -26,7 +26,6 @@ use collections::BTreeSet;
|
|||
use convert::ConvertTarget;
|
||||
use editor::Bias;
|
||||
use editor::Editor;
|
||||
use editor::scroll::Autoscroll;
|
||||
use editor::{Anchor, SelectionEffects};
|
||||
use editor::{display_map::ToDisplayPoint, movement};
|
||||
use gpui::{Context, Window, actions};
|
||||
|
@ -103,7 +102,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
Vim::action(editor, cx, |vim, _: &HelixDelete, window, cx| {
|
||||
vim.record_current_action(cx);
|
||||
vim.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if selection.is_empty() {
|
||||
selection.end = movement::right(map, selection.end)
|
||||
|
@ -377,7 +376,7 @@ impl Vim {
|
|||
self.start_recording(cx);
|
||||
self.switch_mode(Mode::Insert, false, window, cx);
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None));
|
||||
});
|
||||
});
|
||||
|
@ -388,7 +387,7 @@ impl Vim {
|
|||
if self.mode.is_visual() {
|
||||
let current_mode = self.mode;
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if current_mode == Mode::VisualLine {
|
||||
let start_of_line = motion::start_of_line(map, false, selection.start);
|
||||
|
@ -412,7 +411,7 @@ impl Vim {
|
|||
self.start_recording(cx);
|
||||
self.switch_mode(Mode::Insert, false, window, cx);
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| {
|
||||
(
|
||||
first_non_whitespace(map, false, cursor),
|
||||
|
@ -432,7 +431,7 @@ impl Vim {
|
|||
self.start_recording(cx);
|
||||
self.switch_mode(Mode::Insert, false, window, cx);
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| {
|
||||
(next_line_end(map, cursor, 1), SelectionGoal::None)
|
||||
});
|
||||
|
@ -453,7 +452,7 @@ impl Vim {
|
|||
return;
|
||||
};
|
||||
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_anchor_ranges(marks.iter().map(|mark| *mark..*mark))
|
||||
});
|
||||
});
|
||||
|
@ -489,7 +488,7 @@ impl Vim {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
editor.edit_with_autoindent(edits, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| {
|
||||
let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1);
|
||||
let insert_point = motion::end_of_line(map, false, previous_line, 1);
|
||||
|
@ -530,7 +529,7 @@ impl Vim {
|
|||
(end_of_line..end_of_line, "\n".to_string() + &indent)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.maybe_move_cursors_with(|map, cursor, goal| {
|
||||
Motion::CurrentLine.move_point(
|
||||
map,
|
||||
|
@ -607,7 +606,7 @@ impl Vim {
|
|||
.collect::<Vec<_>>();
|
||||
editor.edit(edits, cx);
|
||||
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
if let Some(position) = original_positions.get(&selection.id) {
|
||||
selection.collapse_to(*position, SelectionGoal::None);
|
||||
|
@ -755,7 +754,7 @@ impl Vim {
|
|||
editor.newline(&editor::actions::Newline, window, cx);
|
||||
}
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let point = movement::saturating_left(map, selection.head());
|
||||
selection.collapse_to(point, SelectionGoal::None)
|
||||
|
@ -791,7 +790,7 @@ impl Vim {
|
|||
cx: &mut Context<Editor>,
|
||||
mut positions: HashMap<usize, Anchor>,
|
||||
) {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if let Some(anchor) = positions.remove(&selection.id) {
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
|
|
@ -8,7 +8,6 @@ use editor::{
|
|||
Bias, DisplayPoint,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement::TextLayoutDetails,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Window};
|
||||
use language::Selection;
|
||||
|
@ -40,7 +39,7 @@ impl Vim {
|
|||
editor.transact(window, cx, |editor, window, 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(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let kind = match motion {
|
||||
Motion::NextWordStart { ignore_punctuation }
|
||||
|
@ -114,7 +113,7 @@ impl Vim {
|
|||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
objects_found |= object.expand_selection(map, selection, around);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use collections::HashMap;
|
||||
use editor::{display_map::ToDisplayPoint, scroll::Autoscroll};
|
||||
use editor::{SelectionEffects, display_map::ToDisplayPoint};
|
||||
use gpui::{Context, Window};
|
||||
use language::{Bias, Point, SelectionGoal};
|
||||
use multi_buffer::MultiBufferRow;
|
||||
|
@ -36,7 +36,7 @@ impl Vim {
|
|||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut selection_starts: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Left);
|
||||
selection_starts.insert(selection.id, anchor);
|
||||
|
@ -66,7 +66,7 @@ impl Vim {
|
|||
editor.convert_to_rot47(&Default::default(), window, cx)
|
||||
}
|
||||
}
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = selection_starts.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
@ -90,7 +90,7 @@ impl Vim {
|
|||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
let mut original_positions: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
object.expand_selection(map, selection, around);
|
||||
original_positions.insert(
|
||||
|
@ -116,7 +116,7 @@ impl Vim {
|
|||
editor.convert_to_rot47(&Default::default(), window, cx)
|
||||
}
|
||||
}
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = original_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
@ -239,7 +239,7 @@ impl Vim {
|
|||
.collect::<String>();
|
||||
editor.edit([(range, text)], cx)
|
||||
}
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(cursor_positions)
|
||||
})
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@ use collections::{HashMap, HashSet};
|
|||
use editor::{
|
||||
Bias, DisplayPoint,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Window};
|
||||
use language::{Point, Selection};
|
||||
|
@ -30,7 +29,7 @@ impl Vim {
|
|||
let mut original_columns: HashMap<_, _> = Default::default();
|
||||
let mut motion_kind = None;
|
||||
let mut ranges_to_copy = Vec::new();
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let original_head = selection.head();
|
||||
original_columns.insert(selection.id, original_head.column());
|
||||
|
@ -71,7 +70,7 @@ impl Vim {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head();
|
||||
if kind.linewise() {
|
||||
|
@ -102,7 +101,7 @@ impl Vim {
|
|||
// Emulates behavior in vim where if we expanded backwards to include a newline
|
||||
// the cursor gets set back to the start of the line
|
||||
let mut should_move_to_start: HashSet<_> = Default::default();
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
object.expand_selection(map, selection, around);
|
||||
let offset_range = selection.map(|p| p.to_offset(map, Bias::Left)).range();
|
||||
|
@ -159,7 +158,7 @@ impl Vim {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head();
|
||||
if should_move_to_start.contains(&selection.id) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint, scroll::Autoscroll};
|
||||
use editor::{Editor, MultiBufferSnapshot, ToOffset, ToPoint};
|
||||
use gpui::{Action, Context, Window};
|
||||
use language::{Bias, Point};
|
||||
use schemars::JsonSchema;
|
||||
|
@ -97,7 +97,7 @@ impl Vim {
|
|||
editor.edit(edits, cx);
|
||||
|
||||
let snapshot = editor.buffer().read(cx).snapshot(cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let mut new_ranges = Vec::new();
|
||||
for (visual, anchor) in new_anchors.iter() {
|
||||
let mut point = anchor.to_point(&snapshot);
|
||||
|
|
|
@ -4,7 +4,6 @@ use editor::{
|
|||
Anchor, Bias, DisplayPoint, Editor, MultiBuffer,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Entity, EntityId, UpdateGlobal, Window};
|
||||
use language::SelectionGoal;
|
||||
|
@ -116,7 +115,7 @@ impl Vim {
|
|||
}
|
||||
}
|
||||
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_anchor_ranges(ranges)
|
||||
});
|
||||
})
|
||||
|
@ -169,7 +168,7 @@ impl Vim {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(points.into_iter().map(|p| p..p))
|
||||
})
|
||||
})
|
||||
|
@ -251,7 +250,7 @@ impl Vim {
|
|||
}
|
||||
|
||||
if !should_jump && !ranges.is_empty() {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_anchor_ranges(ranges)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{DisplayPoint, RowExt, display_map::ToDisplayPoint, movement, scroll::Autoscroll};
|
||||
use editor::{DisplayPoint, RowExt, SelectionEffects, display_map::ToDisplayPoint, movement};
|
||||
use gpui::{Action, Context, Window};
|
||||
use language::{Bias, SelectionGoal};
|
||||
use schemars::JsonSchema;
|
||||
|
@ -187,7 +187,7 @@ impl Vim {
|
|||
// and put the cursor on the first non-blank character of the first inserted line (or at the end if the first line is blank).
|
||||
// otherwise vim will insert the next text at (or before) the current cursor position,
|
||||
// the cursor will go to the last (or first, if is_multiline) inserted character.
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.replace_cursors_with(|map| {
|
||||
let mut cursors = Vec::new();
|
||||
for (anchor, line_mode, is_multiline) in &new_selections {
|
||||
|
@ -238,7 +238,7 @@ impl Vim {
|
|||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
object.expand_selection(map, selection, around);
|
||||
});
|
||||
|
@ -252,7 +252,7 @@ impl Vim {
|
|||
};
|
||||
editor.insert(&text, window, cx);
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
selection.start = map.clip_point(selection.start, Bias::Left);
|
||||
selection.end = selection.start
|
||||
|
@ -276,7 +276,7 @@ impl Vim {
|
|||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
motion.expand_selection(
|
||||
map,
|
||||
|
@ -296,7 +296,7 @@ impl Vim {
|
|||
};
|
||||
editor.insert(&text, window, cx);
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
selection.start = map.clip_point(selection.start, Bias::Left);
|
||||
selection.end = selection.start
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{Editor, movement};
|
||||
use editor::{Editor, SelectionEffects, movement};
|
||||
use gpui::{Context, Window, actions};
|
||||
use language::Point;
|
||||
|
||||
|
@ -41,7 +41,7 @@ impl Vim {
|
|||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if selection.start == selection.end {
|
||||
Motion::Right.expand_selection(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{Vim, motion::Motion, object::Object};
|
||||
use collections::HashMap;
|
||||
use editor::{Bias, display_map::ToDisplayPoint};
|
||||
use editor::{Bias, SelectionEffects, display_map::ToDisplayPoint};
|
||||
use gpui::{Context, Window};
|
||||
use language::SelectionGoal;
|
||||
|
||||
|
@ -18,7 +18,7 @@ impl Vim {
|
|||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut selection_starts: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
selection_starts.insert(selection.id, anchor);
|
||||
|
@ -32,7 +32,7 @@ impl Vim {
|
|||
});
|
||||
});
|
||||
editor.toggle_comments(&Default::default(), window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = selection_starts.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
@ -53,7 +53,7 @@ impl Vim {
|
|||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut original_positions: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
original_positions.insert(selection.id, anchor);
|
||||
|
@ -61,7 +61,7 @@ impl Vim {
|
|||
});
|
||||
});
|
||||
editor.toggle_comments(&Default::default(), window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = original_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(anchor.to_display_point(map), SelectionGoal::None);
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
state::{Mode, Register},
|
||||
};
|
||||
use collections::HashMap;
|
||||
use editor::{ClipboardSelection, Editor};
|
||||
use editor::{ClipboardSelection, Editor, SelectionEffects};
|
||||
use gpui::Context;
|
||||
use gpui::Window;
|
||||
use language::Point;
|
||||
|
@ -31,7 +31,7 @@ impl Vim {
|
|||
editor.set_clip_at_line_ends(false, cx);
|
||||
let mut original_positions: HashMap<_, _> = Default::default();
|
||||
let mut kind = None;
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let original_position = (selection.head(), selection.goal);
|
||||
kind = motion.expand_selection(
|
||||
|
@ -51,7 +51,7 @@ impl Vim {
|
|||
});
|
||||
let Some(kind) = kind else { return };
|
||||
vim.yank_selections_content(editor, kind, window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
let (head, goal) = original_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(head, goal);
|
||||
|
@ -73,7 +73,7 @@ impl Vim {
|
|||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
let mut start_positions: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
object.expand_selection(map, selection, around);
|
||||
let start_position = (selection.start, selection.goal);
|
||||
|
@ -81,7 +81,7 @@ impl Vim {
|
|||
});
|
||||
});
|
||||
vim.yank_selections_content(editor, MotionKind::Exclusive, window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
let (head, goal) = start_positions.remove(&selection.id).unwrap();
|
||||
selection.collapse_to(head, goal);
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{
|
|||
state::Mode,
|
||||
};
|
||||
use editor::{
|
||||
Anchor, Bias, Editor, EditorSnapshot, ToOffset, ToPoint, display_map::ToDisplayPoint,
|
||||
scroll::Autoscroll,
|
||||
Anchor, Bias, Editor, EditorSnapshot, SelectionEffects, ToOffset, ToPoint,
|
||||
display_map::ToDisplayPoint,
|
||||
};
|
||||
use gpui::{Context, Window, actions};
|
||||
use language::{Point, SelectionGoal};
|
||||
|
@ -72,7 +72,7 @@ impl Vim {
|
|||
|
||||
editor.edit_with_block_indent(edits.clone(), Vec::new(), cx);
|
||||
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_anchor_ranges(edits.iter().map(|(range, _)| range.end..range.end));
|
||||
});
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
|
@ -124,7 +124,7 @@ impl Vim {
|
|||
|
||||
editor.edit(edits, cx);
|
||||
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges(new_selections);
|
||||
});
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
|
@ -251,7 +251,7 @@ impl Vim {
|
|||
}
|
||||
|
||||
if let Some(position) = final_cursor_position {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|_map, selection| {
|
||||
selection.collapse_to(position, SelectionGoal::None);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{Vim, motion::Motion, object::Object, state::Mode};
|
||||
use collections::HashMap;
|
||||
use editor::{Bias, Editor, RewrapOptions, display_map::ToDisplayPoint, scroll::Autoscroll};
|
||||
use editor::{Bias, Editor, RewrapOptions, SelectionEffects, display_map::ToDisplayPoint};
|
||||
use gpui::{Context, Window, actions};
|
||||
use language::SelectionGoal;
|
||||
|
||||
|
@ -22,7 +22,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if let Some(anchor) = positions.remove(&selection.id) {
|
||||
let mut point = anchor.to_display_point(map);
|
||||
|
@ -53,7 +53,7 @@ impl Vim {
|
|||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut selection_starts: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
selection_starts.insert(selection.id, anchor);
|
||||
|
@ -73,7 +73,7 @@ impl Vim {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = selection_starts.remove(&selection.id).unwrap();
|
||||
let mut point = anchor.to_display_point(map);
|
||||
|
@ -96,7 +96,7 @@ impl Vim {
|
|||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
let mut original_positions: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = map.display_point_to_anchor(selection.head(), Bias::Right);
|
||||
original_positions.insert(selection.id, anchor);
|
||||
|
@ -110,7 +110,7 @@ impl Vim {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = original_positions.remove(&selection.id).unwrap();
|
||||
let mut point = anchor.to_display_point(map);
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
object::Object,
|
||||
state::Mode,
|
||||
};
|
||||
use editor::{Bias, movement, scroll::Autoscroll};
|
||||
use editor::{Bias, movement};
|
||||
use gpui::{Context, Window};
|
||||
use language::BracketPair;
|
||||
|
||||
|
@ -109,7 +109,7 @@ impl Vim {
|
|||
|
||||
editor.edit(edits, cx);
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
if mode == Mode::VisualBlock {
|
||||
s.select_anchor_ranges(anchors.into_iter().take(1))
|
||||
} else {
|
||||
|
@ -207,7 +207,7 @@ impl Vim {
|
|||
}
|
||||
}
|
||||
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(anchors);
|
||||
});
|
||||
edits.sort_by_key(|(range, _)| range.start);
|
||||
|
@ -317,7 +317,7 @@ impl Vim {
|
|||
edits.sort_by_key(|(range, _)| range.start);
|
||||
editor.edit(edits, cx);
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_anchor_ranges(stable_anchors);
|
||||
});
|
||||
});
|
||||
|
@ -375,7 +375,7 @@ impl Vim {
|
|||
anchors.push(start..start)
|
||||
}
|
||||
}
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges(anchors);
|
||||
});
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
|
|
|
@ -22,7 +22,8 @@ mod visual;
|
|||
use anyhow::Result;
|
||||
use collections::HashMap;
|
||||
use editor::{
|
||||
Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, ToPoint,
|
||||
Anchor, Bias, Editor, EditorEvent, EditorSettings, HideMouseCursorOrigin, SelectionEffects,
|
||||
ToPoint,
|
||||
movement::{self, FindRange},
|
||||
};
|
||||
use gpui::{
|
||||
|
@ -963,7 +964,7 @@ impl Vim {
|
|||
}
|
||||
}
|
||||
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
// we cheat with visual block mode and use multiple cursors.
|
||||
// the cost of this cheat is we need to convert back to a single
|
||||
// cursor whenever vim would.
|
||||
|
@ -1163,7 +1164,7 @@ impl Vim {
|
|||
} else {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
selection.collapse_to(selection.start, selection.goal)
|
||||
})
|
||||
|
@ -1438,27 +1439,29 @@ impl Vim {
|
|||
Mode::VisualLine | Mode::VisualBlock | Mode::Visual => {
|
||||
self.update_editor(window, cx, |vim, editor, window, cx| {
|
||||
let original_mode = vim.undo_modes.get(transaction_id);
|
||||
editor.change_selections(None, window, cx, |s| match original_mode {
|
||||
Some(Mode::VisualLine) => {
|
||||
s.move_with(|map, selection| {
|
||||
selection.collapse_to(
|
||||
map.prev_line_boundary(selection.start.to_point(map)).1,
|
||||
SelectionGoal::None,
|
||||
)
|
||||
});
|
||||
}
|
||||
Some(Mode::VisualBlock) => {
|
||||
let mut first = s.first_anchor();
|
||||
first.collapse_to(first.start, first.goal);
|
||||
s.select_anchors(vec![first]);
|
||||
}
|
||||
_ => {
|
||||
s.move_with(|map, selection| {
|
||||
selection.collapse_to(
|
||||
map.clip_at_line_end(selection.start),
|
||||
selection.goal,
|
||||
);
|
||||
});
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
match original_mode {
|
||||
Some(Mode::VisualLine) => {
|
||||
s.move_with(|map, selection| {
|
||||
selection.collapse_to(
|
||||
map.prev_line_boundary(selection.start.to_point(map)).1,
|
||||
SelectionGoal::None,
|
||||
)
|
||||
});
|
||||
}
|
||||
Some(Mode::VisualBlock) => {
|
||||
let mut first = s.first_anchor();
|
||||
first.collapse_to(first.start, first.goal);
|
||||
s.select_anchors(vec![first]);
|
||||
}
|
||||
_ => {
|
||||
s.move_with(|map, selection| {
|
||||
selection.collapse_to(
|
||||
map.clip_at_line_end(selection.start),
|
||||
selection.goal,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1466,7 +1469,7 @@ impl Vim {
|
|||
}
|
||||
Mode::Normal => {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
selection
|
||||
.collapse_to(map.clip_at_line_end(selection.end), selection.goal)
|
||||
|
|
|
@ -2,10 +2,9 @@ use std::sync::Arc;
|
|||
|
||||
use collections::HashMap;
|
||||
use editor::{
|
||||
Bias, DisplayPoint, Editor,
|
||||
Bias, DisplayPoint, Editor, SelectionEffects,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement,
|
||||
scroll::Autoscroll,
|
||||
};
|
||||
use gpui::{Context, Window, actions};
|
||||
use language::{Point, Selection, SelectionGoal};
|
||||
|
@ -133,7 +132,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
|
||||
vim.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let map = s.display_map();
|
||||
let ranges = ranges
|
||||
.into_iter()
|
||||
|
@ -187,7 +186,7 @@ impl Vim {
|
|||
motion.move_point(map, point, goal, times, &text_layout_details)
|
||||
})
|
||||
} else {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let was_reversed = selection.reversed;
|
||||
let mut current_head = selection.head();
|
||||
|
@ -259,7 +258,7 @@ impl Vim {
|
|||
) -> Option<(DisplayPoint, SelectionGoal)>,
|
||||
) {
|
||||
let text_layout_details = editor.text_layout_details(window);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
let map = &s.display_map();
|
||||
let mut head = s.newest_anchor().head().to_display_point(map);
|
||||
let mut tail = s.oldest_anchor().tail().to_display_point(map);
|
||||
|
@ -375,7 +374,7 @@ impl Vim {
|
|||
}
|
||||
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut mut_selection = selection.clone();
|
||||
|
||||
|
@ -454,7 +453,7 @@ impl Vim {
|
|||
) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.split_selection_into_lines(&Default::default(), window, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| {
|
||||
(next_line_end(map, cursor, 1), SelectionGoal::None)
|
||||
});
|
||||
|
@ -472,7 +471,7 @@ impl Vim {
|
|||
) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.split_selection_into_lines(&Default::default(), window, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, _| {
|
||||
(
|
||||
first_non_whitespace(map, false, cursor),
|
||||
|
@ -495,7 +494,7 @@ impl Vim {
|
|||
|
||||
pub fn other_end(&mut self, _: &OtherEnd, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
selection.reversed = !selection.reversed;
|
||||
});
|
||||
|
@ -511,7 +510,7 @@ impl Vim {
|
|||
) {
|
||||
let mode = self.mode;
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|_, selection| {
|
||||
selection.reversed = !selection.reversed;
|
||||
});
|
||||
|
@ -530,7 +529,7 @@ impl Vim {
|
|||
editor.selections.line_mode = false;
|
||||
|
||||
editor.transact(window, cx, |editor, window, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if line_mode {
|
||||
let mut position = selection.head();
|
||||
|
@ -567,7 +566,7 @@ impl Vim {
|
|||
vim.copy_selections_content(editor, kind, window, cx);
|
||||
|
||||
if line_mode && vim.mode != Mode::VisualBlock {
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let end = selection.end.to_point(map);
|
||||
let start = selection.start.to_point(map);
|
||||
|
@ -587,7 +586,7 @@ impl Vim {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head().to_point(map);
|
||||
|
||||
|
@ -613,7 +612,7 @@ impl Vim {
|
|||
|
||||
// For visual line mode, adjust selections to avoid yanking the next line when on \n
|
||||
if line_mode && vim.mode != Mode::VisualBlock {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let start = selection.start.to_point(map);
|
||||
let end = selection.end.to_point(map);
|
||||
|
@ -634,7 +633,7 @@ impl Vim {
|
|||
MotionKind::Exclusive
|
||||
};
|
||||
vim.yank_selections_content(editor, kind, window, cx);
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if line_mode {
|
||||
selection.start = start_of_line(map, false, selection.start);
|
||||
|
@ -687,7 +686,9 @@ impl Vim {
|
|||
}
|
||||
|
||||
editor.edit(edits, cx);
|
||||
editor.change_selections(None, window, cx, |s| s.select_ranges(stable_anchors));
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
s.select_ranges(stable_anchors)
|
||||
});
|
||||
});
|
||||
});
|
||||
self.switch_mode(Mode::Normal, false, window, cx);
|
||||
|
@ -799,7 +800,7 @@ impl Vim {
|
|||
if direction == Direction::Prev {
|
||||
std::mem::swap(&mut start_selection, &mut end_selection);
|
||||
}
|
||||
editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges([start_selection..end_selection]);
|
||||
});
|
||||
editor.set_collapse_matches(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue