Skip to content

Commit

Permalink
fixing normal_mode movement
Browse files Browse the repository at this point in the history
  • Loading branch information
JustBobinAround committed Jan 20, 2025
1 parent 0c77823 commit 76f4ae9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3643,7 +3643,7 @@ fn open_above(cx: &mut Context) {
}

fn normal_mode(cx: &mut Context) {
cx.editor.using_evil_line_selection = false;
evil_extending_normal_mode(cx);
cx.editor.enter_normal_mode();
}

Expand Down Expand Up @@ -6832,3 +6832,35 @@ fn evil_update_last_find_op_prev(editor: &mut Editor, inclusive: bool, ch: char)
});
}
}

fn evil_extending_normal_mode(cx: &mut Context) {
// moves cursor back one when exiting insert mode
// unless the cursor is at the start of the line
let count = cx.count();
if cx.editor.evil {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
let selection = doc.selection(view.id).clone().transform(|range| {
let line = range.cursor_line(text);
let pos = text.line_to_char(line);
if range.head != pos && cx.editor.mode != Mode::Normal {
let text = doc.text().slice(..);
let text_fmt = doc.text_format(view.inner_area(doc).width, None);
let mut annotations = view.text_annotations(doc, None);
move_horizontally(
text,
range,
Direction::Backward,
count,
Movement::Move,
&text_fmt,
&mut annotations,
)
} else {
range
}
});
doc.set_selection(view.id, selection);
}
cx.editor.using_evil_line_selection = false;
}

0 comments on commit 76f4ae9

Please sign in to comment.