diff --git a/yazi-core/src/input/commands/type_.rs b/yazi-core/src/input/commands/type_.rs index 955eeada..f4b90ed8 100644 --- a/yazi-core/src/input/commands/type_.rs +++ b/yazi-core/src/input/commands/type_.rs @@ -52,7 +52,7 @@ impl Input { let snap = self.snap_mut(); snap.cursor = match range.start_bound() { std::ops::Bound::Included(i) => *i, - std::ops::Bound::Excluded(i) => i + 1, + std::ops::Bound::Excluded(_) => unreachable!(), std::ops::Bound::Unbounded => 0, }; if snap.value.drain(range).next().is_some() { @@ -62,15 +62,22 @@ impl Input { false } - fn forward_delete(&mut self) -> bool { + fn backspace(&mut self, under: bool) -> bool { let snap = self.snaps.current_mut(); - if snap.cursor >= snap.value.len() { + if !under && snap.cursor < 1 { + return false; + } else if under && snap.cursor >= snap.value.len() { return false; - } else { - snap.value.remove(snap.idx(snap.cursor).unwrap()); } - self.move_(0); + if under { + snap.value.remove(snap.idx(snap.cursor).unwrap()); + self.move_(0); + } else { + snap.value.remove(snap.idx(snap.cursor - 1).unwrap()); + self.move_(-1); + } + self.flush_value(); true } @@ -99,10 +106,10 @@ impl Input { Key { code: C('f'), shift: false, ctrl: true, alt: false } => self.move_(1), // Delete the character before the cursor - Key { code: Backspace, shift: false, ctrl: false, alt: false } => self.backspace(), - Key { code: C('h'), shift: false, ctrl: true, alt: false } => self.backspace(), + Key { code: Backspace, shift: false, ctrl: false, alt: false } => self.backspace(false), + Key { code: C('h'), shift: false, ctrl: true, alt: false } => self.backspace(false), // Delete the character under the cursor - Key { code: C('d'), shift: false, ctrl: true, alt: false } => self.forward_delete(), + Key { code: C('d'), shift: false, ctrl: true, alt: false } => self.backspace(true), // Move back to the start of the current or previous word Key { code: C('b'), shift: false, ctrl: false, alt: true } => { diff --git a/yazi-core/src/input/input.rs b/yazi-core/src/input/input.rs index 8f085758..2a019c79 100644 --- a/yazi-core/src/input/input.rs +++ b/yazi-core/src/input/input.rs @@ -56,19 +56,6 @@ impl Input { true } - pub fn backspace(&mut self) -> bool { - let snap = self.snaps.current_mut(); - if snap.cursor < 1 { - return false; - } else { - snap.value.remove(snap.idx(snap.cursor - 1).unwrap()); - } - - self.move_(-1); - self.flush_value(); - true - } - pub(super) fn handle_op(&mut self, cursor: usize, include: bool) -> bool { let old = self.snap().clone(); let snap = self.snaps.current_mut();