@@ -1272,19 +1272,13 @@ fn append_mode(cx: &mut Context) {
12721272 doc.restore_cursor = true;
12731273 let text = doc.text().slice(..);
12741274
1275− // TODO: preserve selections, like in `Insert` mode. Probably we'll want
1276− // an explicit separate `Append` mode or something similar, so that we
1277− // don't change the selection at all, and instead just display and edit
1278− // things differently.
1279− let selection = doc
1280− .selection(view.id)
1281− .clone()
1282− .min_width_1(text)
1283− .transform(|range| Range::new(range.to(), range.to()));
1275+ let selection = doc.selection(view.id).clone().min_width_1(text);
12841276
1277+ // Make sure there's room at the end of the document if the last
1278+ // selection butts up against it.
12851279 let end = text.len_chars();
1286−
1287− if selection.iter().any(|range| range.head == end) {
1280+ let last_range = selection.iter().last().unwrap();
1281+ if !last_range.is_empty() && last_range.head == end {
12881282 let transaction = Transaction::change(
12891283 doc.text(),
12901284 std::array::IntoIter::new([(end, end, Some(doc.line_ending.as_str().into()))]),
@@ -1292,7 +1286,15 @@ fn append_mode(cx: &mut Context) {
12921286 doc.apply(&transaction, view.id);
12931287 }
12941288
1295− doc.set_selection(view.id, selection);
1289+ doc.set_selection(
1290+ view.id,
1291+ selection.clone().transform(|range| {
1292+ Range::new(
1293+ range.from(),
1294+ graphemes::next_grapheme_boundary(doc.text().slice(..), range.to()),
1295+ )
1296+ }),
1297+ );
12961298}
12971299
12981300mod cmd {
@@ -2829,11 +2831,11 @@ pub mod insert {
28292831 let (view, doc) = current!(cx.editor);
28302832
28312833 let text = doc.text();
2832− let selection = doc.selection(view.id);
2834+ let selection = doc.selection(view.id).clone().cursors(text.slice(..));
28332835
28342836 // run through insert hooks, stopping on the first one that returns Some(t)
28352837 for hook in HOOKS {
2836− if let Some(transaction) = hook(text, selection, c) {
2838+ if let Some(transaction) = hook(text, &selection, c) {
28372839 doc.apply(&transaction, view.id);
28382840 break;
28392841 }
@@ -2853,7 +2855,11 @@ pub mod insert {
28532855 // indent by one to reach 4 spaces).
28542856
28552857 let indent = Tendril::from(doc.indent_unit());
2856− let transaction = Transaction::insert(doc.text(), doc.selection(view.id), indent);
2858+ let transaction = Transaction::insert(
2859+ doc.text(),
2860+ &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
2861+ indent,
2862+ );
28572863 doc.apply(&transaction, view.id);
28582864 }
28592865
@@ -2862,13 +2868,13 @@ pub mod insert {
28622868 let text = doc.text().slice(..);
28632869
28642870 let contents = doc.text();
2865− let selection = doc.selection(view.id);
2871+ let selection = doc.selection(view.id).clone().cursors(text);
28662872 let mut ranges = SmallVec::with_capacity(selection.len());
28672873
28682874 // TODO: this is annoying, but we need to do it to properly calculate pos after edits
28692875 let mut offs = 0;
28702876
2871− let mut transaction = Transaction::change_by_selection(contents, selection, |range| {
2877+ let mut transaction = Transaction::change_by_selection(contents, &selection, |range| {
28722878 let pos = range.head;
28732879
28742880 let prev = if pos == 0 {