fix: use UnicodeWidthStr to handle VS16/ZWJ grapheme clusters correctly

UnicodeWidthChar on the first char misses grapheme clusters where the
base char is narrow but the full grapheme (with variation selectors)
renders wide. UnicodeWidthStr on the whole symbol string handles all
cases: CJK, emoji with VS16, ZWJ sequences.
This commit is contained in:
June Kim 2026-05-09 10:11:13 -07:00
parent e45329a689
commit 9e78bdcf6e

View file

@ -1,7 +1,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use unicode_width::UnicodeWidthChar;
use unicode_width::UnicodeWidthStr;
use yazi_adapter::ADAPTOR;
pub static COLLISION: AtomicBool = AtomicBool::new(false);
@ -24,8 +24,7 @@ impl Widget for Clear {
if area.x > buf.area.x {
let left = area.x - 1;
for y in area.top()..area.bottom() {
let ch = buf[(left, y)].symbol().chars().next();
if ch.is_some_and(|c| c.width().unwrap_or(0) > 1) {
if buf[(left, y)].symbol().width() > 1 {
buf[(left, y)].reset();
}
}