@@ -1145,15 +1145,14 @@ pub fn prepend_to_line(cx: &mut Context) {
11451145
11461146// A inserts at the end of each line with a selection
11471147pub fn append_to_line(cx: &mut Context) {
1148− move_line_end(cx);
1149−
11501148 let (view, doc) = cx.current();
11511149 enter_insert_mode(doc);
11521150
1153− // offset by another 1 char since move_line_end will position on the last char, we want to
1154− // append past that
11551151 let selection = doc.selection(view.id).transform(|range| {
1156− let pos = range.head + 1;
1152+ let text = doc.text();
1153+ let line = text.char_to_line(range.head);
1154+ // we can't use line_to_char(line + 1) - 2 because the last line might not contain \n
1155+ let pos = (text.line_to_char(line) + text.line(line).len_chars()).saturating_sub(1);
11571156 Range::new(pos, pos)
11581157 });
11591158 doc.set_selection(view.id, selection);