mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-23 15:51:03 +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;
|
||||
|
||||
#[cfg(windows)]
|
||||
const SEPARATOR: [char; 2] = ['/', '\\'];
|
||||
|
||||
#[cfg(not(windows))]
|
||||
const SEPARATOR: char = std::path::MAIN_SEPARATOR;
|
||||
|
||||
pub struct Opt {
|
||||
word: String,
|
||||
ticket: usize,
|
||||
|
|
@ -59,7 +65,7 @@ impl Completion {
|
|||
));
|
||||
}
|
||||
|
||||
Ok::<(), anyhow::Error>(())
|
||||
Ok::<_, anyhow::Error>(())
|
||||
});
|
||||
|
||||
render!(mem::replace(&mut self.visible, false));
|
||||
|
|
@ -67,7 +73,7 @@ impl Completion {
|
|||
|
||||
#[inline]
|
||||
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()),
|
||||
None => (".".to_owned(), s.to_owned()),
|
||||
}
|
||||
|
|
@ -80,7 +86,7 @@ mod tests {
|
|||
|
||||
#[cfg(unix)]
|
||||
#[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()));
|
||||
|
|
@ -92,7 +98,7 @@ mod tests {
|
|||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn test_explode() {
|
||||
fn test_split() {
|
||||
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\\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 crate::input::Input;
|
||||
|
||||
#[cfg(windows)]
|
||||
const SEPARATOR: [char; 2] = ['/', '\\'];
|
||||
|
||||
#[cfg(not(windows))]
|
||||
const SEPARATOR: char = std::path::MAIN_SEPARATOR;
|
||||
|
||||
pub struct Opt {
|
||||
word: String,
|
||||
ticket: usize,
|
||||
|
|
@ -26,10 +32,10 @@ impl Input {
|
|||
}
|
||||
|
||||
let [before, after] = self.partition();
|
||||
let new = if let Some((prefix, _)) = before.rsplit_once(MAIN_SEPARATOR) {
|
||||
format!("{prefix}/{}{after}", opt.word)
|
||||
let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) {
|
||||
format!("{prefix}/{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
|
||||
} else {
|
||||
format!("{}{after}", opt.word)
|
||||
format!("{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
|
||||
};
|
||||
|
||||
let snap = self.snaps.current_mut();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue