Skip to content

Commit d266d59

Browse files
bestgopherdjc
authored andcommitted
fix: πŸ› remove double-width characters correctly
Signed-off-by: εˆ˜ζ΄‹ <[email protected]> Signed-off-by: bestgopher <[email protected]>
1 parent 00d5fdb commit d266d59

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

β€Žsrc/term.rsβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,10 @@ impl Term {
336336
loop {
337337
match slf.read_key()? {
338338
Key::Backspace => {
339-
if prefix_len < chars.len() && chars.pop().is_some() {
340-
slf.clear_chars(1)?;
339+
if prefix_len < chars.len() {
340+
if let Some(ch) = chars.pop() {
341+
slf.clear_chars(crate::utils::char_width(ch))?;
342+
}
341343
}
342344
slf.flush()?;
343345
}

β€Žsrc/utils.rsβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ fn str_width(s: &str) -> usize {
719719
}
720720

721721
#[cfg(feature = "ansi-parsing")]
722-
fn char_width(c: char) -> usize {
722+
pub(crate) fn char_width(c: char) -> usize {
723723
#[cfg(feature = "unicode-width")]
724724
{
725725
use unicode_width::UnicodeWidthChar;
@@ -732,6 +732,11 @@ fn char_width(c: char) -> usize {
732732
}
733733
}
734734

735+
#[cfg(not(feature = "ansi-parsing"))]
736+
pub(crate) fn char_width(_c: char) -> usize {
737+
1
738+
}
739+
735740
/// Truncates a string to a certain number of characters.
736741
///
737742
/// This ensures that escape codes are not screwed up in the process.

0 commit comments

Comments
Β (0)