mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: support cjk
This commit is contained in:
parent
8f414a4c6b
commit
1182ce69ec
2 changed files with 24 additions and 2 deletions
|
|
@ -39,8 +39,9 @@ impl Input {
|
||||||
));
|
));
|
||||||
|
|
||||||
let (limit, snap) = (self.limit(), self.snap_mut());
|
let (limit, snap) = (self.limit(), self.snap_mut());
|
||||||
let offset =
|
let offset = InputSnap::find_window_backward(&snap.value, snap.cursor, limit / 2)
|
||||||
snap.cursor.saturating_sub(limit / 2).min(snap.len().saturating_sub(limit.saturating_sub(1)));
|
.start
|
||||||
|
.min(InputSnap::find_window_backward(&snap.value, snap.value.chars().count(), limit).start);
|
||||||
if snap.offset != offset {
|
if snap.offset != offset {
|
||||||
snap.offset = offset;
|
snap.offset = offset;
|
||||||
} else if snap.value.is_empty() {
|
} else if snap.value.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -87,4 +87,25 @@ impl InputSnap {
|
||||||
}
|
}
|
||||||
*v.first().unwrap()..v.last().unwrap() + 1
|
*v.first().unwrap()..v.last().unwrap() + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn find_window_backward(s: &str, offset: usize, limit: usize) -> Range<usize> {
|
||||||
|
let mut width = 0;
|
||||||
|
let len = s.chars().count();
|
||||||
|
let v: Vec<_> = s
|
||||||
|
.chars()
|
||||||
|
.rev()
|
||||||
|
.enumerate()
|
||||||
|
.skip(len.saturating_sub(offset + 1))
|
||||||
|
.map_while(|(i, c)| {
|
||||||
|
width += c.width().unwrap_or(0);
|
||||||
|
if width < limit { Some(len.saturating_sub(i + 1)) } else { None }
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if v.is_empty() {
|
||||||
|
return 0..0;
|
||||||
|
}
|
||||||
|
*v.last().unwrap()..v.first().unwrap() + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue