mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
move implement of slash and backslash path complete to Windows specific code
This commit is contained in:
parent
debae675dc
commit
d9f48a90f9
2 changed files with 19 additions and 7 deletions
|
|
@ -67,10 +67,17 @@ impl Completion {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn split_path(s: &str) -> (String, String) {
|
fn split_path(s: &str) -> (String, String) {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
match s.rsplit_once(['/', '\\']) {
|
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()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
match s.rsplit_once(MAIN_SEPARATOR) {
|
||||||
|
Some((p, c)) => (format!("{p}{}", MAIN_SEPARATOR), c.to_owned()),
|
||||||
|
None => (".".to_owned(), s.to_owned()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
use std::path::MAIN_SEPARATOR_STR;
|
|
||||||
|
|
||||||
use yazi_shared::{event::Cmd, render};
|
use yazi_shared::{event::Cmd, render};
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
@ -26,21 +24,28 @@ impl Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
let [before, after] = self.partition();
|
let [before, after] = self.partition();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
let new = if let Some((prefix, _)) = before.rsplit_once(['/', '\\']) {
|
let new = if let Some((prefix, _)) = before.rsplit_once(['/', '\\']) {
|
||||||
|
format!("{prefix}/{}{after}", opt.word).replace(['/', '\\'], std::path::MAIN_SEPARATOR_STR)
|
||||||
|
} else {
|
||||||
|
format!("{}{after}", opt.word).replace(['/', '\\'], std::path::MAIN_SEPARATOR_STR)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
let new = if let Some((prefix, _)) = before.rsplit_once(std::path::MAIN_SEPARATOR) {
|
||||||
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 normalized_new == snap.value {
|
if new == snap.value {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta = normalized_new.chars().count() as isize - snap.value.chars().count() as isize;
|
let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
|
||||||
snap.value = normalized_new;
|
snap.value = new;
|
||||||
|
|
||||||
self.move_(delta);
|
self.move_(delta);
|
||||||
self.flush_value();
|
self.flush_value();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue