Commit d23320eb authored by AdminXVII's avatar AdminXVII

Replace all movements

parent 751d4da7
Pipeline #4513 passed with stage
in 1 minute and 54 seconds
......@@ -299,7 +299,7 @@ impl<'a, W: io::Write> Editor<'a, W> {
/// current_history_loc if set). If started with forward true then incremental search goes
/// forward (top to bottom) other wise reverse (bottom to top). It is valid to continue a
/// search with forward changed (i.e. reverse search direction for one result).
pub fn search(&mut self, forward: bool) -> io::Result<()> {
pub fn search(&mut self, forward: bool) {
if !self.is_search() {
self.freshen_history();
self.refresh_search(forward);
......@@ -322,8 +322,6 @@ impl<'a, W: io::Write> Editor<'a, W> {
None
};
}
self.display()?;
Ok(())
}
pub fn flush(&mut self) -> io::Result<()> {
......@@ -545,9 +543,9 @@ impl<'a, W: io::Write> Editor<'a, W> {
}
/// Move up (backwards) in history.
pub fn move_up(&mut self) -> io::Result<()> {
pub fn move_up(&mut self) {
if self.is_search() {
self.search(false)
self.search(false);
} else {
self.hist_buf_valid = false;
self.freshen_history();
......@@ -580,14 +578,13 @@ impl<'a, W: io::Write> Editor<'a, W> {
}
self.move_cursor_to_end_of_line();
self.no_newline = true;
self.display()
}
}
/// Move down (forwards) in history, or to the new buffer if we reach the end of history.
pub fn move_down(&mut self) -> io::Result<()> {
pub fn move_down(&mut self) {
if self.is_search() {
self.search(true)
self.search(true);
} else {
self.hist_buf_valid = false;
if self.new_buf.num_chars() > 0 {
......@@ -612,12 +609,11 @@ impl<'a, W: io::Write> Editor<'a, W> {
}
self.move_cursor_to_end_of_line();
self.no_newline = true;
self.display()
}
}
/// Moves to the start of history (ie. the earliest history entry).
pub fn move_to_start_of_history(&mut self) -> io::Result<()> {
pub fn move_to_start_of_history(&mut self) {
self.hist_buf_valid = false;
if self.context.history.len() > 0 {
self.cur_history_loc = Some(0);
......@@ -625,19 +621,15 @@ impl<'a, W: io::Write> Editor<'a, W> {
} else {
self.cur_history_loc = None;
}
self.no_newline = true;
self.display()
}
/// Moves to the end of history (ie. the new buffer).
pub fn move_to_end_of_history(&mut self) -> io::Result<()> {
pub fn move_to_end_of_history(&mut self) {
self.hist_buf_valid = false;
if self.cur_history_loc.is_some() {
self.cur_history_loc = None;
self.move_cursor_to_end_of_line();
}
self.no_newline = true;
self.display()
}
/// Inserts a string directly after the cursor, moving the cursor to the right.
......
......@@ -49,8 +49,14 @@ impl Emacs {
ed.display()
}
'd' => ed.delete_after_cursor(),
'p' => ed.move_up(),
'n' => ed.move_down(),
'p' => {
ed.move_up();
ed.display()
}
'n' => {
ed.move_down();
ed.display()
}
'u' => ed.delete_all_before_cursor(),
'k' => ed.delete_all_after_cursor(),
'w' => ed.delete_word_before_cursor(true),
......@@ -64,8 +70,16 @@ impl Emacs {
fn handle_alt_key<'a, W: Write>(&mut self, c: char, ed: &mut Editor<'a, W>) -> io::Result<()> {
match c {
'<' => ed.move_to_start_of_history(),
'>' => ed.move_to_end_of_history(),
'<' => {
ed.move_to_start_of_history();
ed.no_newline = true;
ed.display()
}
'>' => {
ed.move_to_end_of_history();
ed.no_newline = true;
ed.display()
}
'\x7F' => ed.delete_word_before_cursor(true),
'f' => {
emacs_move_word(ed, EmacsMoveDir::Right);
......@@ -151,8 +165,14 @@ impl KeyMap for Emacs {
ed.no_newline = true;
ed.display()
}
Key::Up => ed.move_up(),
Key::Down => ed.move_down(),
Key::Up => {
ed.move_up();
ed.display()
}
Key::Down => {
ed.move_down();
ed.display()
}
Key::Home => {
ed.move_cursor_to_start_of_line();
......
......@@ -48,10 +48,12 @@ pub trait KeyMap: Default {
editor.accept_autosuggestion()?;
}
Key::Ctrl('r') => {
editor.search(false)?;
editor.search(false);
editor.display()?;
}
Key::Ctrl('s') => {
editor.search(true)?;
editor.search(true);
editor.display()?;
}
Key::Right
if editor.is_currently_showing_autosuggestion()
......
......@@ -510,8 +510,14 @@ impl Vi {
ed.no_newline = true;
ed.display()
}
Key::Up => ed.move_up(),
Key::Down => ed.move_down(),
Key::Up => {
ed.move_up();
ed.display()
}
Key::Down => {
ed.move_down();
ed.display()
}
Key::Home => {
ed.move_cursor_to_start_of_line();
ed.no_newline = true;
......@@ -590,7 +596,8 @@ impl Vi {
self.count = 0;
self.movement_reset = true;
ed.current_buffer_mut().end_undo_group();
ed.move_up()?;
ed.move_up();
ed.display()?;
ed.current_buffer_mut().start_undo_group();
Ok(())
}
......@@ -598,7 +605,8 @@ impl Vi {
self.count = 0;
self.movement_reset = true;
ed.current_buffer_mut().end_undo_group();
ed.move_down()?;
ed.move_down();
ed.display()?;
ed.current_buffer_mut().start_undo_group();
Ok(())
}
......@@ -727,11 +735,13 @@ impl Vi {
self.pop_mode_after_movement(Exclusive, ed)
}
Key::Char('k') | Key::Up => {
ed.move_up()?;
ed.move_up();
ed.display()?;
self.pop_mode_after_movement(Exclusive, ed)
}
Key::Char('j') | Key::Down => {
ed.move_down()?;
ed.move_down();
ed.display()?;
self.pop_mode_after_movement(Exclusive, ed)
}
Key::Char('t') => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment