@@ -186,6 +186,7 @@ pub fn insert_mode(view: &mut View, _count: usize) {
186// inserts at the end of each selection
186// inserts at the end of each selection
187pub fn append_mode(view: &mut View, _count: usize) {
187pub fn append_mode(view: &mut View, _count: usize) {
188 view.state.mode = Mode::Insert;
188 view.state.mode = Mode::Insert;
189+ view.state.restore_cursor = true;
190 // TODO: as transaction
191 // TODO: as transaction
191 let text = &view.state.doc.slice(..);
192 let text = &view.state.doc.slice(..);
@@ -268,8 +269,20 @@ pub fn open_below(view: &mut View, _count: usize) {
268// O inserts a new line before each line with a selection
269// O inserts a new line before each line with a selection
270pub fn normal_mode(view: &mut View, _count: usize) {
271pub fn normal_mode(view: &mut View, _count: usize) {
271− // TODO: if leaving append mode, move cursor back by 1
272 view.state.mode = Mode::Normal;
272 view.state.mode = Mode::Normal;
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| {
280+ graphemes::prev_grapheme_boundary(text, range.to()),
284+ view.state.restore_cursor = false;
275// TODO: insert means add text just before cursor, on exit we should be on the last letter.
288// TODO: insert means add text just before cursor, on exit we should be on the last letter.