@@ -50,9 +50,10 @@ pub fn move_line_end(view: &mut View, count: usize) {
5050 .into_iter()
5151 .map(|index| {
5252 // adjust all positions to the end of the line.
53− let line = view.state.doc.line(index);
54− let line_start = view.state.doc.line_to_char(index);
55− line_start + line.len_chars() - 1
53+
54+ // Line end is pos at the start of next line - 1
55+ // subtract another 1 because the line ends with \n
56+ view.state.doc.line_to_char(index + 1).saturating_sub(2)
5657 })
5758 .map(|pos| Range::new(pos, pos));
5859
@@ -236,10 +237,8 @@ pub fn open_below(view: &mut View, _count: usize) {
236237 let positions: Vec<_> = lines
237238 .into_iter()
238239 .map(|index| {
239− // adjust all positions to the end of the line.
240− let line = view.state.doc.line(index);
241− let line_start = view.state.doc.line_to_char(index);
242− line_start + line.len_chars()
240+ // adjust all positions to the end of the line/start of the next one.
241+ view.state.doc.line_to_char(index + 1)
243242 })
244243 .collect();
245244