Passing tests and removed local argument. Also pulled autoscroll argument out to change_selections
This commit is contained in:
parent
c9dcfff607
commit
db0a9114c2
19 changed files with 351 additions and 397 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::{state::Mode, Vim};
|
||||
use editor::Bias;
|
||||
use editor::{Autoscroll, Bias};
|
||||
use gpui::{actions, MutableAppContext, ViewContext};
|
||||
use language::SelectionGoal;
|
||||
use workspace::Workspace;
|
||||
|
@ -13,7 +13,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
fn normal_before(_: &mut Workspace, _: &NormalBefore, cx: &mut ViewContext<Workspace>) {
|
||||
Vim::update(cx, |state, cx| {
|
||||
state.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, mut cursor, _| {
|
||||
*cursor.column_mut() = cursor.column().saturating_sub(1);
|
||||
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
};
|
||||
use change::init as change_init;
|
||||
use collections::HashSet;
|
||||
use editor::{Bias, DisplayPoint};
|
||||
use editor::{Autoscroll, Bias, DisplayPoint};
|
||||
use gpui::{actions, MutableAppContext, ViewContext};
|
||||
use language::SelectionGoal;
|
||||
use workspace::Workspace;
|
||||
|
@ -76,7 +76,7 @@ pub fn normal_motion(motion: Motion, cx: &mut MutableAppContext) {
|
|||
|
||||
fn move_cursor(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, goal| motion.move_point(map, cursor, goal))
|
||||
})
|
||||
});
|
||||
|
@ -86,7 +86,7 @@ fn insert_after(_: &mut Workspace, _: &InsertAfter, cx: &mut ViewContext<Workspa
|
|||
Vim::update(cx, |vim, cx| {
|
||||
vim.switch_mode(Mode::Insert, cx);
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, goal| {
|
||||
Motion::Right.move_point(map, cursor, goal)
|
||||
});
|
||||
|
@ -103,7 +103,7 @@ fn insert_first_non_whitespace(
|
|||
Vim::update(cx, |vim, cx| {
|
||||
vim.switch_mode(Mode::Insert, cx);
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, goal| {
|
||||
Motion::FirstNonWhitespace.move_point(map, cursor, goal)
|
||||
});
|
||||
|
@ -116,7 +116,7 @@ fn insert_end_of_line(_: &mut Workspace, _: &InsertEndOfLine, cx: &mut ViewConte
|
|||
Vim::update(cx, |vim, cx| {
|
||||
vim.switch_mode(Mode::Insert, cx);
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, goal| {
|
||||
Motion::EndOfLine.move_point(map, cursor, goal)
|
||||
});
|
||||
|
@ -145,7 +145,7 @@ fn insert_line_above(_: &mut Workspace, _: &InsertLineAbove, cx: &mut ViewContex
|
|||
(start_of_line..start_of_line, new_text)
|
||||
});
|
||||
editor.edit_with_autoindent(edits, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, mut cursor, _| {
|
||||
*cursor.row_mut() -= 1;
|
||||
*cursor.column_mut() = map.line_len(cursor.row());
|
||||
|
@ -176,7 +176,7 @@ fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContex
|
|||
new_text.push_str(&" ".repeat(indent as usize));
|
||||
(end_of_line..end_of_line, new_text)
|
||||
});
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_cursors_with(|map, cursor, goal| {
|
||||
Motion::EndOfLine.move_point(map, cursor, goal)
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{motion::Motion, state::Mode, Vim};
|
||||
use editor::{char_kind, movement};
|
||||
use editor::{char_kind, movement, Autoscroll};
|
||||
use gpui::{impl_actions, MutableAppContext, ViewContext};
|
||||
use serde::Deserialize;
|
||||
use workspace::Workspace;
|
||||
|
@ -22,7 +22,7 @@ pub fn change_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||
editor.transact(cx, |editor, cx| {
|
||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
motion.expand_selection(map, selection, false);
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ fn change_word(
|
|||
editor.transact(cx, |editor, cx| {
|
||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if selection.end.column() == map.line_len(selection.end.row()) {
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{motion::Motion, Vim};
|
||||
use collections::HashMap;
|
||||
use editor::Bias;
|
||||
use editor::{Autoscroll, Bias};
|
||||
use gpui::MutableAppContext;
|
||||
|
||||
pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
||||
|
@ -8,7 +8,7 @@ pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||
editor.transact(cx, |editor, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
let mut original_columns: HashMap<_, _> = Default::default();
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let original_head = selection.head();
|
||||
motion.expand_selection(map, selection, true);
|
||||
|
@ -19,7 +19,7 @@ pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head();
|
||||
if motion.linewise() {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::ops::{Deref, Range};
|
|||
use collections::BTreeMap;
|
||||
use itertools::{Either, Itertools};
|
||||
|
||||
use editor::display_map::ToDisplayPoint;
|
||||
use editor::{display_map::ToDisplayPoint, Autoscroll};
|
||||
use gpui::{json::json, keymap::Keystroke, ViewHandle};
|
||||
use indoc::indoc;
|
||||
use language::Selection;
|
||||
|
@ -128,7 +128,7 @@ impl<'a> VimTestContext<'a> {
|
|||
let (unmarked_text, markers) = marked_text(&text);
|
||||
editor.set_text(unmarked_text, cx);
|
||||
let cursor_offset = markers[0];
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.replace_cursors_with(|map| vec![cursor_offset.to_display_point(map)])
|
||||
});
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::Bias;
|
||||
use editor::{Autoscroll, Bias};
|
||||
use gpui::{actions, MutableAppContext, ViewContext};
|
||||
use workspace::Workspace;
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
pub fn visual_motion(motion: Motion, cx: &mut MutableAppContext) {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let (new_head, goal) = motion.move_point(map, selection.head(), selection.goal);
|
||||
let new_head = map.clip_at_line_end(new_head);
|
||||
|
@ -42,7 +42,7 @@ pub fn change(_: &mut Workspace, _: &VisualChange, cx: &mut ViewContext<Workspac
|
|||
Vim::update(cx, |vim, cx| {
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if !selection.reversed {
|
||||
// Head was at the end of the selection, and now is at the start. We need to move the end
|
||||
|
@ -63,7 +63,7 @@ pub fn delete(_: &mut Workspace, _: &VisualDelete, cx: &mut ViewContext<Workspac
|
|||
vim.switch_mode(Mode::Normal, cx);
|
||||
vim.update_active_editor(cx, |editor, cx| {
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if !selection.reversed {
|
||||
// Head was at the end of the selection, and now is at the start. We need to move the end
|
||||
|
@ -77,7 +77,7 @@ pub fn delete(_: &mut Workspace, _: &VisualDelete, cx: &mut ViewContext<Workspac
|
|||
|
||||
// Fixup cursor position after the deletion
|
||||
editor.set_clip_at_line_ends(true, cx);
|
||||
editor.change_selections(true, cx, |s| {
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head();
|
||||
cursor = map.clip_point(cursor, Bias::Left);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue