Add clip_to_line_end to display_map/snapshot and set it to ensure vim positioning in normal mode

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Keith Simmons 2022-03-25 18:09:37 -07:00
parent bb9b36dccd
commit 0aaf270650
10 changed files with 142 additions and 104 deletions

View file

@ -3,7 +3,7 @@ use gpui::{action, keymap::Binding, MutableAppContext, ViewContext};
use language::SelectionGoal;
use workspace::Workspace;
use crate::{editor_utils::VimEditorExt, Mode, SwitchMode, VimState};
use crate::{Mode, SwitchMode, VimState};
action!(InsertBefore);
action!(MoveLeft);
@ -29,7 +29,7 @@ pub fn init(cx: &mut MutableAppContext) {
fn move_left(_: &mut Workspace, _: &MoveLeft, cx: &mut ViewContext<Workspace>) {
VimState::update_active_editor(cx, |editor, cx| {
editor.adjusted_move_cursors(cx, |map, mut cursor, _| {
editor.move_cursors(cx, |map, mut cursor, _| {
*cursor.column_mut() = cursor.column().saturating_sub(1);
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)
});
@ -38,19 +38,19 @@ fn move_left(_: &mut Workspace, _: &MoveLeft, cx: &mut ViewContext<Workspace>) {
fn move_down(_: &mut Workspace, _: &MoveDown, cx: &mut ViewContext<Workspace>) {
VimState::update_active_editor(cx, |editor, cx| {
editor.adjusted_move_cursors(cx, movement::down);
editor.move_cursors(cx, movement::down);
});
}
fn move_up(_: &mut Workspace, _: &MoveUp, cx: &mut ViewContext<Workspace>) {
VimState::update_active_editor(cx, |editor, cx| {
editor.adjusted_move_cursors(cx, movement::up);
editor.move_cursors(cx, movement::up);
});
}
fn move_right(_: &mut Workspace, _: &MoveRight, cx: &mut ViewContext<Workspace>) {
VimState::update_active_editor(cx, |editor, cx| {
editor.adjusted_move_cursors(cx, |map, mut cursor, _| {
editor.move_cursors(cx, |map, mut cursor, _| {
*cursor.column_mut() += 1;
(map.clip_point(cursor, Bias::Right), SelectionGoal::None)
});