fix: backspace --under didn't map UTF-8 character code points to byte indices (#2010)

This commit is contained in:
三咲雅 · Misaki Masa 2024-12-07 22:53:22 +08:00 committed by GitHub
parent 8ec944dbd3
commit 6308873f0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ impl Input {
let snap = self.snaps.current_mut();
if !opt.under && snap.cursor < 1 {
return;
} else if opt.under && snap.cursor >= snap.value.len() {
} else if opt.under && snap.cursor >= snap.count() {
return;
}

View file

@ -44,7 +44,7 @@ impl Input {
return;
}
let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
let delta = new.chars().count() as isize - snap.count() as isize;
snap.value = new;
self.move_(delta);

View file

@ -32,7 +32,7 @@ impl InputSnap {
#[inline]
pub(super) fn reset(&mut self, limit: usize) {
self.cursor = self.cursor.min(self.value.chars().count().saturating_sub(self.mode.delta()));
self.cursor = self.cursor.min(self.count().saturating_sub(self.mode.delta()));
self.offset =
self.offset.min(self.cursor.saturating_sub(Self::find_window(&self.rev(), 0, limit).end));
}