@@ -186,6 +186,7 @@ pub fn insert_mode(view: &mut View, _count: usize) {
186186// inserts at the end of each selection
187187pub fn append_mode(view: &mut View, _count: usize) {
188188 view.state.mode = Mode::Insert;
189+ view.state.restore_cursor = true;
189190
190191 // TODO: as transaction
191192 let text = &view.state.doc.slice(..);
@@ -268,8 +269,20 @@ pub fn open_below(view: &mut View, _count: usize) {
268269// O inserts a new line before each line with a selection
269270
270271pub fn normal_mode(view: &mut View, _count: usize) {
271− // TODO: if leaving append mode, move cursor back by 1
272272 view.state.mode = Mode::Normal;
273+
274+ // if leaving append mode, move cursor back by 1
275+ if view.state.restore_cursor {
276+ let text = &view.state.doc.slice(..);
277+ view.state.selection = view.state.selection.transform(|range| {
278+ Range::new(
279+ range.from(),
280+ graphemes::prev_grapheme_boundary(text, range.to()),
281+ )
282+ });
283+
284+ view.state.restore_cursor = false;
285+ }
273286}
274287
275288// TODO: insert means add text just before cursor, on exit we should be on the last letter.