From ca0cdc0bbbbdcfbaae5530f4cc9c69008e0bb20a Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 4 Jan 2025 10:43:58 +0800 Subject: [PATCH] Move `type_str` and `replace_str` to `type` and `replace` commands --- yazi-core/src/input/commands/replace.rs | 11 +++++++++++ yazi-core/src/input/commands/type_.rs | 14 ++++++++++++++ yazi-core/src/input/input.rs | 24 ------------------------ yazi-fm/src/app/app.rs | 3 +-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/yazi-core/src/input/commands/replace.rs b/yazi-core/src/input/commands/replace.rs index 775c3e37..7daf22d9 100644 --- a/yazi-core/src/input/commands/replace.rs +++ b/yazi-core/src/input/commands/replace.rs @@ -13,4 +13,15 @@ impl Input { render!(); } } + + pub fn replace_str(&mut self, s: &str) { + let snap = self.snaps.current_mut(); + + let start = snap.idx(snap.cursor).unwrap(); + let end = snap.idx(snap.cursor + 1).unwrap(); + snap.value.replace_range(start..end, s); + + self.flush_value(); + render!(); + } } diff --git a/yazi-core/src/input/commands/type_.rs b/yazi-core/src/input/commands/type_.rs index 4692f545..6ff23142 100644 --- a/yazi-core/src/input/commands/type_.rs +++ b/yazi-core/src/input/commands/type_.rs @@ -1,4 +1,5 @@ use yazi_config::keymap::Key; +use yazi_macro::render; use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode}; @@ -34,4 +35,17 @@ impl Input { false } + + pub fn type_str(&mut self, s: &str) { + let snap = self.snaps.current_mut(); + if snap.cursor < 1 { + snap.value.insert_str(0, s); + } else { + snap.value.insert_str(snap.idx(snap.cursor).unwrap(), s); + } + + self.move_(s.chars().count() as isize); + self.flush_value(); + render!(); + } } diff --git a/yazi-core/src/input/input.rs b/yazi-core/src/input/input.rs index d34b6ca9..532e8d1f 100644 --- a/yazi-core/src/input/input.rs +++ b/yazi-core/src/input/input.rs @@ -33,30 +33,6 @@ impl Input { self.position.offset.width.saturating_sub(INPUT.border()) as usize } - pub fn type_str(&mut self, s: &str) { - let snap = self.snaps.current_mut(); - if snap.cursor < 1 { - snap.value.insert_str(0, s); - } else { - snap.value.insert_str(snap.idx(snap.cursor).unwrap(), s); - } - - self.move_(s.chars().count() as isize); - self.flush_value(); - render!(); - } - - pub fn replace_str(&mut self, s: &str) { - let snap = self.snaps.current_mut(); - - let start = snap.idx(snap.cursor).unwrap(); - let end = snap.idx(snap.cursor + 1).unwrap(); - snap.value.replace_range(start..end, s); - - self.flush_value(); - render!(); - } - pub(super) fn handle_op(&mut self, cursor: usize, include: bool) -> bool { let old = self.snap().clone(); let snap = self.snaps.current_mut(); diff --git a/yazi-fm/src/app/app.rs b/yazi-fm/src/app/app.rs index 64a15cfd..2a8fb106 100644 --- a/yazi-fm/src/app/app.rs +++ b/yazi-fm/src/app/app.rs @@ -92,8 +92,7 @@ impl App { let input = &mut self.cx.input; if input.mode() == InputMode::Insert { input.type_str(&str); - } - if input.mode() == InputMode::Replace { + } else if input.mode() == InputMode::Replace { input.replace_str(&str); } }