aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-07 08:17:14 +0000
committerBlaž Hrastnik2020-09-07 08:17:14 +0000
commit67017e533691e383363079dccbecbb2afb021be5 (patch)
tree6aec447ec0117dcb3810d747e0791607e9db062d
parentdd749bb2846584aa20078cfa2aea4fe18678c12c (diff)
append mode
-rw-r--r--helix-core/src/commands.rs5
-rw-r--r--helix-term/src/keymap.rs4
2 files changed, 8 insertions, 1 deletions
diff --git a/helix-core/src/commands.rs b/helix-core/src/commands.rs
index c4e9f092..37d59946 100644
--- a/helix-core/src/commands.rs
+++ b/helix-core/src/commands.rs
@@ -1,3 +1,4 @@
+use crate::graphemes::next_grapheme_boundary;
use crate::selection::Range;
use crate::state::{Direction, Granularity, Mode, State};
use crate::transaction::{ChangeSet, Transaction};
@@ -74,9 +75,10 @@ pub fn append_mode(state: &mut State, _count: usize) {
state.mode = Mode::Insert;
// TODO: as transaction
+ let text = &state.doc.slice(..);
state.selection = state.selection.clone().transform(|range| {
// TODO: to() + next char
- Range::new(range.from(), range.to())
+ Range::new(range.from(), next_grapheme_boundary(text, range.to()))
})
}
@@ -86,6 +88,7 @@ pub fn append_mode(state: &mut State, _count: usize) {
// O inserts a new line after each line with a selection
pub fn normal_mode(state: &mut State, _count: usize) {
+ // TODO: if leaving append mode, move cursor back by 1
state.mode = Mode::Normal;
}
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index ddbff3ea..4b176b61 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -121,6 +121,10 @@ pub fn default() -> Keymap {
modifiers: Modifiers::NONE
} => commands::insert_mode as Command,
Key {
+ code: KeyCode::Char('a'),
+ modifiers: Modifiers::NONE
+ } => commands::append_mode as Command,
+ Key {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
} => commands::normal_mode as Command,