diff --git a/src/term.rs b/src/term.rs index 88f5d964..89054a27 100644 --- a/src/term.rs +++ b/src/term.rs @@ -336,8 +336,10 @@ impl Term { loop { match slf.read_key()? { Key::Backspace => { - if prefix_len < chars.len() && chars.pop().is_some() { - slf.clear_chars(1)?; + if prefix_len < chars.len() { + if let Some(ch) = chars.pop() { + slf.clear_chars(crate::utils::char_width(ch))?; + } } slf.flush()?; } diff --git a/src/utils.rs b/src/utils.rs index 378c9e65..a6cf37d6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -719,7 +719,7 @@ fn str_width(s: &str) -> usize { } #[cfg(feature = "ansi-parsing")] -fn char_width(c: char) -> usize { +pub(crate) fn char_width(c: char) -> usize { #[cfg(feature = "unicode-width")] { use unicode_width::UnicodeWidthChar; @@ -732,6 +732,11 @@ fn char_width(c: char) -> usize { } } +#[cfg(not(feature = "ansi-parsing"))] +pub(crate) fn char_width(_c: char) -> usize { + 1 +} + /// Truncates a string to a certain number of characters. /// /// This ensures that escape codes are not screwed up in the process.