1use editor::Bias;
2use gpui::{action, keymap::Binding, MutableAppContext, ViewContext};
3use language::SelectionGoal;
4use workspace::Workspace;
5
6use crate::{mode::Mode, SwitchMode, VimState};
7
8action!(NormalBefore);
9
10pub fn init(cx: &mut MutableAppContext) {
11 let context = Some("Editor && vim_mode == insert");
12 cx.add_bindings(vec![
13 Binding::new("escape", NormalBefore, context),
14 Binding::new("ctrl-c", NormalBefore, context),
15 ]);
16
17 cx.add_action(normal_before);
18}
19
20fn normal_before(_: &mut Workspace, _: &NormalBefore, cx: &mut ViewContext<Workspace>) {
21 VimState::update_global(cx, |state, cx| {
22 state.update_active_editor(cx, |editor, cx| {
23 editor.move_cursors(cx, |map, mut cursor, _| {
24 *cursor.column_mut() = cursor.column().saturating_sub(1);
25 (map.clip_point(cursor, Bias::Left), SelectionGoal::None)
26 });
27 });
28 state.switch_mode(&SwitchMode(Mode::Normal), cx);
29 })
30}