feat: cd path auto-completion supports ~ expansion

This commit is contained in:
sxyazi 2024-05-23 17:03:24 +08:00
parent 58e5d2280a
commit 68f5f7faff
No known key found for this signature in database
2 changed files with 9 additions and 4 deletions

View file

@ -1,7 +1,7 @@
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
use tokio::fs;
use yazi_shared::{emit, event::{Cmd, Data}, render, Layer};
use yazi_shared::{emit, event::{Cmd, Data}, fs::expand_path, render, Layer};
use crate::completion::Completion;
@ -74,9 +74,12 @@ impl Completion {
#[inline]
fn split_path(s: &str) -> (String, String) {
let p = expand_path(s);
let s = p.to_string_lossy();
match s.rsplit_once(SEPARATOR) {
Some((p, c)) => (format!("{p}{}", MAIN_SEPARATOR), c.to_owned()),
None => (".".to_owned(), s.to_owned()),
None => (".".to_owned(), s.into_owned()),
}
}
}

View file

@ -1,6 +1,6 @@
use std::path::MAIN_SEPARATOR_STR;
use yazi_shared::{event::{Cmd, Data}, render};
use yazi_shared::{event::{Cmd, Data}, fs::expand_path, render};
use crate::input::Input;
@ -32,7 +32,9 @@ impl Input {
}
let [before, after] = self.partition();
let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) {
let before = expand_path(before);
let new = if let Some((prefix, _)) = before.to_string_lossy().rsplit_once(SEPARATOR) {
format!("{prefix}/{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)
} else {
format!("{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)