diff options
author | Blaž Hrastnik | 2020-09-05 13:01:05 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-09-07 02:21:26 +0000 |
commit | 579b6899f1fe7f0a06857c4528f55f316e2975e9 (patch) | |
tree | 1b850ba7f2abc1698763fc55cf7eebdad0fe9c8f /helix-core/src/commands.rs | |
parent | e806446379db3f5c7e3bc6fd823ddd6969ed6f32 (diff) |
Work on insert mode.
Diffstat (limited to 'helix-core/src/commands.rs')
-rw-r--r-- | helix-core/src/commands.rs | 22 |
1 files changed, 21 insertions, 1 deletions
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); +} |