diff --git a/TODO.md b/TODO.md index da12f0839019b60376baaa2006f48ab661998ffe..4e63b04ec82ad8e6bfd4d255b749a1b0ffbff54f 100644 --- a/TODO.md +++ b/TODO.md @@ -7,7 +7,8 @@ Known bugs: - [x] When using `t` with a char that isn't in the document, Sodium will crash. -- [x] `d<motion>` does not do anything if: 1) the motion moves to the end of a line. 2) if the motion moves to the last line. +- [x] `dG` on the last line of the file deletes from the cursor to the end of the line, instead of the entire line. + Not sure if intended. The bug causing these two bugs, is localised to be in position.rs. It resolves by returning a value one over bound x diff --git a/src/caret/motion.rs b/src/caret/motion.rs index 62fae2da0bd8a7eb7e80d3c568772b7ff116368c..2f1a70ab2761374a416f52113939aca06217789e 100644 --- a/src/caret/motion.rs +++ b/src/caret/motion.rs @@ -62,7 +62,6 @@ impl Editor { pub fn to_motion_unbounded(&mut self, Inst(n, cmd): Inst) -> Option<(isize, isize)> { use io::key::Key::*; - let x = self.x(); let y = self.y(); match cmd.key { @@ -71,8 +70,8 @@ impl Editor { Char('j') => Some(self.down_unbounded(n.d())), Char('k') => Some(self.up_unbounded(n.d())), Char('g') => Some((0, n.or(1) as isize - 1)), - Char('G') => Some((0, self.buffers.current_buffer().len() as isize - 1)), - Char('L') => Some(to_signed_pos((x, self.buffers.current_buffer()[y].len()))), + Char('G') => Some((self.buffers.current_buffer()[y].len() as isize, self.buffers.current_buffer().len() as isize - 1)), + Char('L') => Some(to_signed_pos((self.buffers.current_buffer()[y].len(), y))), Char('H') => Some((0, y as isize)), Char('t') => { diff --git a/src/edit/buffer.rs b/src/edit/buffer.rs index 69819c4bdcdad572db35cd8dc22e285287c4de75..b40f59c8d89a2fe832f8006bfe74e5fc8e168033 100644 --- a/src/edit/buffer.rs +++ b/src/edit/buffer.rs @@ -146,7 +146,11 @@ impl<'a> TextBuffer<'a> for SplitBuffer { self.before.remove(n) } else if n < self.len() { let n = self.len() - 1 - n; - self.after.remove(n) + let ret = self.after.remove(n); + if n == 0 { + self.up(); + } + ret } else { panic!("Out of bound"); } diff --git a/src/edit/selection.rs b/src/edit/selection.rs index 32fe1a55b6ce4eeca7ce54f5126704369ce9f337..64143eacae66b508c55ab654326baa267e0f1fa0 100644 --- a/src/edit/selection.rs +++ b/src/edit/selection.rs @@ -7,8 +7,8 @@ impl Editor { /// defines a position on the same line, only the characters from the current position to the /// motion's position are removed. pub fn remove_rb<'a>(&mut self, (x, y): (isize, isize)) { - if y == self.y() as isize { - let (x, y) = self.bound((x as usize, y as usize), true); + if y == (self.y() as isize ) { + let (x, y) = self.bound((x as usize, y as usize), false); // Single line mode let (a, b) = if self.x() > x { (x, self.x())