fix: panic replacing character in empty input

This commit is contained in:
darcy 2025-01-08 13:32:15 +11:00 committed by sxyazi
parent 14f3ca55d2
commit 053426a489
No known key found for this signature in database

View file

@ -17,8 +17,14 @@ impl Input {
pub fn replace_str(&mut self, s: &str) {
let snap = self.snap_mut();
if snap.value.is_empty() {
snap.mode = InputMode::Normal;
render!();
return;
}
let start = snap.idx(snap.cursor).unwrap();
let end = snap.idx(snap.cursor + 1).unwrap(); // FIXME: panic if the input is empty while in replace mode
let end = snap.idx(snap.cursor + 1).unwrap();
snap.mode = InputMode::Normal;
snap.value.replace_range(start..end, s);