mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
better path completion
This commit is contained in:
parent
a70374fced
commit
debae675dc
2 changed files with 8 additions and 6 deletions
|
|
@ -67,7 +67,7 @@ impl Completion {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn split_path(s: &str) -> (String, String) {
|
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()),
|
Some((p, c)) => (format!("{p}{}", MAIN_SEPARATOR), c.to_owned()),
|
||||||
None => (".".to_owned(), s.to_owned()),
|
None => (".".to_owned(), s.to_owned()),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::path::MAIN_SEPARATOR;
|
use std::path::MAIN_SEPARATOR_STR;
|
||||||
|
|
||||||
use yazi_shared::{event::Cmd, render};
|
use yazi_shared::{event::Cmd, render};
|
||||||
|
|
||||||
|
|
@ -26,19 +26,21 @@ impl Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
let [before, after] = self.partition();
|
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)
|
format!("{prefix}/{}{after}", opt.word)
|
||||||
} else {
|
} else {
|
||||||
format!("{}{after}", opt.word)
|
format!("{}{after}", opt.word)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let normalized_new = new.replace(['/', '\\'], MAIN_SEPARATOR_STR);
|
||||||
|
|
||||||
let snap = self.snaps.current_mut();
|
let snap = self.snaps.current_mut();
|
||||||
if new == snap.value {
|
if normalized_new == snap.value {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
|
let delta = normalized_new.chars().count() as isize - snap.value.chars().count() as isize;
|
||||||
snap.value = new;
|
snap.value = normalized_new;
|
||||||
|
|
||||||
self.move_(delta);
|
self.move_(delta);
|
||||||
self.flush_value();
|
self.flush_value();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue