Fix bug on ^W.
This commit is contained in:
parent
5eef3dd811
commit
3021fdb848
2 changed files with 9 additions and 13 deletions
|
@ -40,20 +40,17 @@ impl Buffer {
|
||||||
self.content.push(value);
|
self.content.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove last char. Return true if a char was removed.
|
// Remove last char.
|
||||||
pub fn strip_char(&mut self) -> bool {
|
pub fn strip_char(&mut self) {
|
||||||
// Reset error message.
|
// Reset error message.
|
||||||
self.message = None;
|
self.message = None;
|
||||||
if self.content.pop().is_some() {
|
if self.content.pop().is_some() {
|
||||||
self.altered = true;
|
self.altered = true;
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove last word. Return true if a word was removed.
|
// Remove last word.
|
||||||
pub fn strip_word(&mut self) -> bool {
|
pub fn strip_word(&mut self) {
|
||||||
// Reset error message.
|
// Reset error message.
|
||||||
self.message = None;
|
self.message = None;
|
||||||
let iter = UnicodeSegmentation::split_word_bound_indices(
|
let iter = UnicodeSegmentation::split_word_bound_indices(
|
||||||
|
@ -62,9 +59,6 @@ impl Buffer {
|
||||||
if let Some((index, _)) = iter.last() {
|
if let Some((index, _)) = iter.last() {
|
||||||
self.content.truncate(index);
|
self.content.truncate(index);
|
||||||
self.altered = true;
|
self.altered = true;
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ pub fn run(
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Escape ^W, and ^U clear input buffer.
|
// Escape and ^U clear input buffer.
|
||||||
Key::Esc | Key::Ctrl('u') => {
|
Key::Esc | Key::Ctrl('u') => {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
|
@ -247,7 +247,8 @@ pub fn run(
|
||||||
},
|
},
|
||||||
// ^W removes last word.
|
// ^W removes last word.
|
||||||
Key::Ctrl('w') => {
|
Key::Ctrl('w') => {
|
||||||
if !buffer.strip_word() {
|
buffer.strip_word();
|
||||||
|
if buffer.is_empty() {
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
|
@ -255,7 +256,8 @@ pub fn run(
|
||||||
// Backspace.
|
// Backspace.
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
// Delete last char in buffer.
|
// Delete last char in buffer.
|
||||||
if buffer.strip_char() && buffer.is_empty() {
|
buffer.strip_char();
|
||||||
|
if buffer.is_empty() {
|
||||||
insert_mode = false;
|
insert_mode = false;
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue