on master help sign in
append mode
67017e5Blaž Hrastnik
helix-core/src/commands.rs+4−1
@@ -1,3 +1,4 @@
1+use crate::graphemes::next_grapheme_boundary;
1use crate::selection::Range;
2use crate::selection::Range;
2use crate::state::{Direction, Granularity, Mode, State};
3use crate::state::{Direction, Granularity, Mode, State};
3use crate::transaction::{ChangeSet, Transaction};
4use crate::transaction::{ChangeSet, Transaction};
@@ -74,9 +75,10 @@ pub fn append_mode(state: &mut State, _count: usize) {
74 state.mode = Mode::Insert;
75 state.mode = Mode::Insert;
75
76
76 // TODO: as transaction
77 // TODO: as transaction
78+ let text = &state.doc.slice(..);
77 state.selection = state.selection.clone().transform(|range| {
79 state.selection = state.selection.clone().transform(|range| {
78 // TODO: to() + next char
80 // TODO: to() + next char
79− Range::new(range.from(), range.to())
81+ Range::new(range.from(), next_grapheme_boundary(text, range.to()))
80 })
82 })
81}
83}
82
84
@@ -86,6 +88,7 @@ pub fn append_mode(state: &mut State, _count: usize) {
86// O inserts a new line after each line with a selection
88// O inserts a new line after each line with a selection
87
89
88pub fn normal_mode(state: &mut State, _count: usize) {
90pub fn normal_mode(state: &mut State, _count: usize) {
91+ // TODO: if leaving append mode, move cursor back by 1
89 state.mode = Mode::Normal;
92 state.mode = Mode::Normal;
90}
93}
91
94
helix-term/src/keymap.rs+4
@@ -120,6 +120,10 @@ pub fn default() -> Keymap {
120 code: KeyCode::Char('i'),
120 code: KeyCode::Char('i'),
121 modifiers: Modifiers::NONE
121 modifiers: Modifiers::NONE
122 } => commands::insert_mode as Command,
122 } => commands::insert_mode as Command,
123+ Key {
124+ code: KeyCode::Char('a'),
125+ modifiers: Modifiers::NONE
126+ } => commands::append_mode as Command,
123 Key {
127 Key {
124 code: KeyCode::Esc,
128 code: KeyCode::Esc,
125 modifiers: Modifiers::NONE
129 modifiers: Modifiers::NONE