mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: bracketed paste (Ctrl-v from the terminal) also needs to exit replace mode
This commit is contained in:
parent
ca0cdc0bbb
commit
44755143db
6 changed files with 16 additions and 24 deletions
|
|
@ -17,7 +17,7 @@ impl From<bool> for Opt {
|
|||
impl Input {
|
||||
#[yazi_codegen::command]
|
||||
pub fn backspace(&mut self, opt: Opt) {
|
||||
let snap = self.snaps.current_mut();
|
||||
let snap = self.snap_mut();
|
||||
if !opt.under && snap.cursor < 1 {
|
||||
return;
|
||||
} else if opt.under && snap.cursor >= snap.count() {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl Input {
|
|||
format!("{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
|
||||
};
|
||||
|
||||
let snap = self.snaps.current_mut();
|
||||
let snap = self.snap_mut();
|
||||
if new == snap.value {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ impl Input {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: need to create a new snap for each replace operation, otherwise we
|
||||
// can't undo/redo it with `u` and `Ctrl-r`
|
||||
pub fn replace_str(&mut self, s: &str) {
|
||||
let snap = self.snaps.current_mut();
|
||||
let snap = self.snap_mut();
|
||||
|
||||
let start = snap.idx(snap.cursor).unwrap();
|
||||
let end = snap.idx(snap.cursor + 1).unwrap();
|
||||
let end = snap.idx(snap.cursor + 1).unwrap(); // FIXME: panic if the input is empty while in replace mode
|
||||
|
||||
snap.mode = InputMode::Normal;
|
||||
snap.value.replace_range(start..end, s);
|
||||
|
||||
self.flush_value();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl Input {
|
|||
|
||||
// Set cursor after reset
|
||||
if let Some(cursor) = opt.cfg.cursor {
|
||||
self.snaps.current_mut().cursor = cursor;
|
||||
self.snap_mut().cursor = cursor;
|
||||
self.move_(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,32 +12,21 @@ impl From<CmdCow> for Opt {
|
|||
|
||||
impl Input {
|
||||
pub fn type_(&mut self, key: &Key) -> bool {
|
||||
if self.mode() == InputMode::Replace {
|
||||
let Some(c) = key.plain() else {
|
||||
return false;
|
||||
};
|
||||
let Some(c) = key.plain() else { return false };
|
||||
|
||||
let snap = self.snaps.current_mut();
|
||||
snap.mode = InputMode::Normal;
|
||||
self.replace_str(c.encode_utf8(&mut [0; 4]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if self.mode() != InputMode::Insert {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(c) = key.plain() {
|
||||
if self.mode() == InputMode::Insert {
|
||||
self.type_str(c.encode_utf8(&mut [0; 4]));
|
||||
return true;
|
||||
} else if self.mode() == InputMode::Replace {
|
||||
self.replace_str(c.encode_utf8(&mut [0; 4]));
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn type_str(&mut self, s: &str) {
|
||||
let snap = self.snaps.current_mut();
|
||||
let snap = self.snap_mut();
|
||||
if snap.cursor < 1 {
|
||||
snap.value.insert_str(0, s);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use std::ops::Range;
|
|||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use yazi_config::{INPUT, popup::Position};
|
||||
use yazi_macro::render;
|
||||
use yazi_plugin::CLIPBOARD;
|
||||
use yazi_shared::errors::InputError;
|
||||
|
||||
|
|
@ -35,7 +34,7 @@ impl Input {
|
|||
|
||||
pub(super) fn handle_op(&mut self, cursor: usize, include: bool) -> bool {
|
||||
let old = self.snap().clone();
|
||||
let snap = self.snaps.current_mut();
|
||||
let snap = self.snap_mut();
|
||||
|
||||
match snap.op {
|
||||
InputOp::None | InputOp::Select(_) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue