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