diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index eca488e740026..4dbdf416a09f4 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1904,9 +1904,15 @@ impl Editor { if doc.restore_cursor { let text = doc.text().slice(..); let selection = doc.selection(view.id).clone().transform(|range| { + // only move back when + let mut head = range.to(); + if range.head > range.anchor { + head = graphemes::prev_grapheme_boundary(text, head); + } + Range::new( range.from(), - graphemes::prev_grapheme_boundary(text, range.to()), + head ) });