mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Move type_str and replace_str to type and replace commands
This commit is contained in:
parent
a652aab632
commit
ca0cdc0bbb
4 changed files with 26 additions and 26 deletions
|
|
@ -13,4 +13,15 @@ impl Input {
|
||||||
render!();
|
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!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use yazi_config::keymap::Key;
|
use yazi_config::keymap::Key;
|
||||||
|
use yazi_macro::render;
|
||||||
use yazi_shared::event::CmdCow;
|
use yazi_shared::event::CmdCow;
|
||||||
|
|
||||||
use crate::input::{Input, InputMode};
|
use crate::input::{Input, InputMode};
|
||||||
|
|
@ -34,4 +35,17 @@ impl Input {
|
||||||
|
|
||||||
false
|
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!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,30 +33,6 @@ impl Input {
|
||||||
self.position.offset.width.saturating_sub(INPUT.border()) as usize
|
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 {
|
pub(super) fn handle_op(&mut self, cursor: usize, include: bool) -> bool {
|
||||||
let old = self.snap().clone();
|
let old = self.snap().clone();
|
||||||
let snap = self.snaps.current_mut();
|
let snap = self.snaps.current_mut();
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,7 @@ impl App {
|
||||||
let input = &mut self.cx.input;
|
let input = &mut self.cx.input;
|
||||||
if input.mode() == InputMode::Insert {
|
if input.mode() == InputMode::Insert {
|
||||||
input.type_str(&str);
|
input.type_str(&str);
|
||||||
}
|
} else if input.mode() == InputMode::Replace {
|
||||||
if input.mode() == InputMode::Replace {
|
|
||||||
input.replace_str(&str);
|
input.replace_str(&str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue