on master help sign in
append mode
commit67017e533691e383363079dccbecbb2afb021be5 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 7 Sep 2020, 17:17 (6 years ago) parentdd749bb
2 files changed+8−1
helix-core/src/commands.rs+4−1 helix-term/src/keymap.rs+4
helix-core/src/commands.rs+4−1
@@ -1,3 +1,4 @@
1+use crate::graphemes::next_grapheme_boundary;
12use crate::selection::Range;
23use crate::state::{Direction, Granularity, Mode, State};
34use crate::transaction::{ChangeSet, Transaction};
@@ -74,9 +75,10 @@ pub fn append_mode(state: &mut State, _count: usize) {
7475 state.mode = Mode::Insert;
7576
7677 // TODO: as transaction
78+ let text = &state.doc.slice(..);
7779 state.selection = state.selection.clone().transform(|range| {
7880 // TODO: to() + next char
79− Range::new(range.from(), range.to())
81+ Range::new(range.from(), next_grapheme_boundary(text, range.to()))
8082 })
8183}
8284
@@ -86,6 +88,7 @@ pub fn append_mode(state: &mut State, _count: usize) {
8688// O inserts a new line after each line with a selection
8789
8890pub fn normal_mode(state: &mut State, _count: usize) {
91+ // TODO: if leaving append mode, move cursor back by 1
8992 state.mode = Mode::Normal;
9093}
9194
helix-term/src/keymap.rs+4
@@ -120,6 +120,10 @@ pub fn default() -> Keymap {
120120 code: KeyCode::Char('i'),
121121 modifiers: Modifiers::NONE
122122 } => commands::insert_mode as Command,
123+ Key {
124+ code: KeyCode::Char('a'),
125+ modifiers: Modifiers::NONE
126+ } => commands::append_mode as Command,
123127 Key {
124128 code: KeyCode::Esc,
125129 modifiers: Modifiers::NONE