aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/commands.rs')
-rw-r--r--helix-core/src/commands.rs22
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);
+}