mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: trigger path completion with both / and \ on Windows (#909)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
a70374fced
commit
f442ae2adf
2 changed files with 20 additions and 8 deletions
|
|
@ -5,6 +5,12 @@ use yazi_shared::{emit, event::Cmd, render, Layer};
|
||||||
|
|
||||||
use crate::completion::Completion;
|
use crate::completion::Completion;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
const SEPARATOR: [char; 2] = ['/', '\\'];
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const SEPARATOR: char = std::path::MAIN_SEPARATOR;
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
word: String,
|
word: String,
|
||||||
ticket: usize,
|
ticket: usize,
|
||||||
|
|
@ -59,7 +65,7 @@ impl Completion {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok::<(), anyhow::Error>(())
|
Ok::<_, anyhow::Error>(())
|
||||||
});
|
});
|
||||||
|
|
||||||
render!(mem::replace(&mut self.visible, false));
|
render!(mem::replace(&mut self.visible, false));
|
||||||
|
|
@ -67,7 +73,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(SEPARATOR) {
|
||||||
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()),
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +86,7 @@ mod tests {
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_explode() {
|
fn test_split() {
|
||||||
assert_eq!(Completion::split_path(""), (".".to_owned(), "".to_owned()));
|
assert_eq!(Completion::split_path(""), (".".to_owned(), "".to_owned()));
|
||||||
assert_eq!(Completion::split_path(" "), (".".to_owned(), " ".to_owned()));
|
assert_eq!(Completion::split_path(" "), (".".to_owned(), " ".to_owned()));
|
||||||
assert_eq!(Completion::split_path("/"), ("/".to_owned(), "".to_owned()));
|
assert_eq!(Completion::split_path("/"), ("/".to_owned(), "".to_owned()));
|
||||||
|
|
@ -92,7 +98,7 @@ mod tests {
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_explode() {
|
fn test_split() {
|
||||||
assert_eq!(Completion::split_path("foo"), (".".to_owned(), "foo".to_owned()));
|
assert_eq!(Completion::split_path("foo"), (".".to_owned(), "foo".to_owned()));
|
||||||
assert_eq!(Completion::split_path("foo\\"), ("foo\\".to_owned(), "".to_owned()));
|
assert_eq!(Completion::split_path("foo\\"), ("foo\\".to_owned(), "".to_owned()));
|
||||||
assert_eq!(Completion::split_path("foo\\bar"), ("foo\\".to_owned(), "bar".to_owned()));
|
assert_eq!(Completion::split_path("foo\\bar"), ("foo\\".to_owned(), "bar".to_owned()));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
use std::path::MAIN_SEPARATOR;
|
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;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
const SEPARATOR: [char; 2] = ['/', '\\'];
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const SEPARATOR: char = std::path::MAIN_SEPARATOR;
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
word: String,
|
word: String,
|
||||||
ticket: usize,
|
ticket: usize,
|
||||||
|
|
@ -26,10 +32,10 @@ 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(SEPARATOR) {
|
||||||
format!("{prefix}/{}{after}", opt.word)
|
format!("{prefix}/{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
|
||||||
} else {
|
} else {
|
||||||
format!("{}{after}", opt.word)
|
format!("{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
|
||||||
};
|
};
|
||||||
|
|
||||||
let snap = self.snaps.current_mut();
|
let snap = self.snaps.current_mut();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue