Fix bug on ^W.

This commit is contained in:
shy 2021-04-12 08:52:19 +02:00
parent 5eef3dd811
commit 3021fdb848
2 changed files with 9 additions and 13 deletions

View file

@ -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
}
}

View file

@ -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;
}