mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
extract forward_delete into independent function
This commit is contained in:
parent
a76664a6fa
commit
060ffd0411
1 changed files with 30 additions and 21 deletions
|
|
@ -56,11 +56,17 @@ impl Input {
|
|||
}
|
||||
|
||||
match key {
|
||||
Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => self.backspace(false),
|
||||
Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => self.backspace(),
|
||||
// Handle Emacs-style keybindings.
|
||||
Key { code: KeyCode::Char('a'), shift: false, ctrl: true, alt: false } => self.move_(isize::MIN),
|
||||
Key { code: KeyCode::Char('e'), shift: false, ctrl: true, alt: false } => self.move_(isize::MAX),
|
||||
Key { code: KeyCode::Char('d'), shift: false, ctrl: true, alt: false } => self.backspace(true),
|
||||
Key { code: KeyCode::Char('a'), shift: false, ctrl: true, alt: false } => {
|
||||
self.move_(isize::MIN)
|
||||
}
|
||||
Key { code: KeyCode::Char('e'), shift: false, ctrl: true, alt: false } => {
|
||||
self.move_(isize::MAX)
|
||||
}
|
||||
Key { code: KeyCode::Char('d'), shift: false, ctrl: true, alt: false } => {
|
||||
self.forward_delete()
|
||||
}
|
||||
Key { code: KeyCode::Char('b'), shift: false, ctrl: false, alt: true } => self.backward(),
|
||||
Key { code: KeyCode::Char('f'), shift: false, ctrl: false, alt: true } => self.forward(false),
|
||||
_ => false,
|
||||
|
|
@ -80,9 +86,8 @@ impl Input {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self, forward_delete: bool) -> bool {
|
||||
pub fn forward_delete(&mut self) -> bool {
|
||||
let snap = self.snaps.current_mut();
|
||||
if forward_delete {
|
||||
// Return false when there is no character on the right to delete.
|
||||
// Note that the cursor can be at index `snap.value.len()` when in
|
||||
// edit mode.
|
||||
|
|
@ -92,14 +97,18 @@ impl Input {
|
|||
snap.value.remove(snap.idx(snap.cursor).unwrap());
|
||||
}
|
||||
self.move_(0);
|
||||
} else {
|
||||
self.flush_value();
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue