diff --git a/src/buffer.rs b/src/buffer.rs index 007d675..a6a409a 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -40,20 +40,17 @@ impl Buffer { self.content.push(value); } - // Remove last char. Return true if a char was removed. - pub fn strip_char(&mut self) -> bool { + // Remove last char. + pub fn strip_char(&mut self) { // Reset error message. self.message = None; if self.content.pop().is_some() { self.altered = true; - true - } else { - false } } - // Remove last word. Return true if a word was removed. - pub fn strip_word(&mut self) -> bool { + // Remove last word. + pub fn strip_word(&mut self) { // Reset error message. self.message = None; let iter = UnicodeSegmentation::split_word_bound_indices( @@ -62,9 +59,6 @@ impl Buffer { if let Some((index, _)) = iter.last() { self.content.truncate(index); self.altered = true; - true - } else { - false } } diff --git a/src/lib.rs b/src/lib.rs index 648fbe2..86092ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -239,7 +239,7 @@ pub fn run( layout.force_redraw = true; } }, - // Escape ^W, and ^U clear input buffer. + // Escape and ^U clear input buffer. Key::Esc | Key::Ctrl('u') => { buffer.reset(); insert_mode = false; @@ -247,7 +247,8 @@ pub fn run( }, // ^W removes last word. Key::Ctrl('w') => { - if !buffer.strip_word() { + buffer.strip_word(); + if buffer.is_empty() { insert_mode = false; layout.force_redraw = true; } @@ -255,7 +256,8 @@ pub fn run( // Backspace. Key::Backspace => { // Delete last char in buffer. - if buffer.strip_char() && buffer.is_empty() { + buffer.strip_char(); + if buffer.is_empty() { insert_mode = false; layout.force_redraw = true; }