From 579b6899f1fe7f0a06857c4528f55f316e2975e9 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sat, 5 Sep 2020 22:01:05 +0900 Subject: Work on insert mode. --- helix-core/src/commands.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'helix-core/src/commands.rs') diff --git a/helix-core/src/commands.rs b/helix-core/src/commands.rs index 62e97686..a6b74449 100644 --- a/helix-core/src/commands.rs +++ b/helix-core/src/commands.rs @@ -1,4 +1,4 @@ -use crate::state::{Direction, Granularity, State}; +use crate::state::{Direction, Granularity, Mode, State}; /// A command is a function that takes the current state and a count, and does a side-effect on the /// state (usually by creating and applying a transaction). @@ -48,3 +48,23 @@ pub fn move_line_down(state: &mut State, count: usize) { count, ); } + +pub fn insert_mode(state: &mut State, _count: usize) { + state.mode = Mode::Insert; +} + +pub fn normal_mode(state: &mut State, _count: usize) { + state.mode = Mode::Normal; +} + +// TODO: insert means add text just before cursor, on exit we should be on the last letter. +pub fn insert(state: &mut State, c: char) { + // TODO: needs to work with multiple cursors + use crate::transaction::ChangeSet; + + let pos = state.selection.primary().head; + let changes = ChangeSet::insert(&state.doc, pos, c); + // TODO: need to store history + changes.apply(state.contents_mut()); + state.selection = state.selection.clone().map(&changes); +} -- cgit v1.2.3-70-g09d2