better path completion

This commit is contained in:
Nguyen Duc Toan 2024-04-14 12:20:52 +07:00
parent a70374fced
commit debae675dc
No known key found for this signature in database
GPG key ID: B96F4A160C6B3251
2 changed files with 8 additions and 6 deletions

View file

@ -67,7 +67,7 @@ impl Completion {
#[inline]
fn split_path(s: &str) -> (String, String) {
match s.rsplit_once(MAIN_SEPARATOR) {
match s.rsplit_once(['/', '\\']) {
Some((p, c)) => (format!("{p}{}", MAIN_SEPARATOR), c.to_owned()),
None => (".".to_owned(), s.to_owned()),
}

View file

@ -1,4 +1,4 @@
use std::path::MAIN_SEPARATOR;
use std::path::MAIN_SEPARATOR_STR;
use yazi_shared::{event::Cmd, render};
@ -26,19 +26,21 @@ impl Input {
}
let [before, after] = self.partition();
let new = if let Some((prefix, _)) = before.rsplit_once(MAIN_SEPARATOR) {
let new = if let Some((prefix, _)) = before.rsplit_once(['/', '\\']) {
format!("{prefix}/{}{after}", opt.word)
} else {
format!("{}{after}", opt.word)
};
let normalized_new = new.replace(['/', '\\'], MAIN_SEPARATOR_STR);
let snap = self.snaps.current_mut();
if new == snap.value {
if normalized_new == snap.value {
return;
}
let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
snap.value = new;
let delta = normalized_new.chars().count() as isize - snap.value.chars().count() as isize;
snap.value = normalized_new;
self.move_(delta);
self.flush_value();