mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: URL covariance for selected and yanked files
This commit is contained in:
parent
9535caad5b
commit
1b98b74606
4 changed files with 31 additions and 17 deletions
|
|
@ -115,12 +115,12 @@ mod tests {
|
|||
fn test_split() {
|
||||
yazi_fs::init();
|
||||
compare("foo", "", "foo");
|
||||
compare("foo\\", "foo\\", "");
|
||||
compare("foo\\bar", "foo\\", "bar");
|
||||
compare("foo\\bar\\", "foo\\bar\\", "");
|
||||
compare("C:\\", "C:\\", "");
|
||||
compare("C:\\foo", "C:\\", "foo");
|
||||
compare("C:\\foo\\", "C:\\foo\\", "");
|
||||
compare("C:\\foo\\bar", "C:\\foo\\", "bar");
|
||||
compare(r"foo\", r"foo\", "");
|
||||
compare(r"foo\bar", r"foo\", "bar");
|
||||
compare(r"foo\bar\", r"foo\bar\", "");
|
||||
compare(r"C:\", r"C:\", "");
|
||||
compare(r"C:\foo", r"C:\", "foo");
|
||||
compare(r"C:\foo\", r"C:\foo\", "");
|
||||
compare(r"C:\foo\bar", r"C:\foo\", "bar");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
// FIXME: VFS
|
||||
use std::{ffi::OsString, path::Path};
|
||||
use std::ffi::OsString;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use yazi_macro::{act, succ};
|
||||
|
|
@ -28,13 +27,24 @@ impl Actor for Copy {
|
|||
.peekable();
|
||||
|
||||
while let Some(u) = it.next() {
|
||||
s.push(match opt.r#type.as_ref() {
|
||||
"path" => opt.separator.transform(u),
|
||||
"dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))),
|
||||
"filename" => opt.separator.transform(u.name()),
|
||||
"name_without_ext" => opt.separator.transform(u.file_stem().unwrap_or_default()),
|
||||
match opt.r#type.as_ref() {
|
||||
// TODO: rename to "url"
|
||||
"path" => {
|
||||
s.push(opt.separator.transform(&u.os_str()));
|
||||
}
|
||||
"dirname" => {
|
||||
if let Some(p) = u.parent_url() {
|
||||
s.push(opt.separator.transform(&p.os_str()));
|
||||
}
|
||||
}
|
||||
"filename" => {
|
||||
s.push(opt.separator.transform(u.name()));
|
||||
}
|
||||
"name_without_ext" => {
|
||||
s.push(opt.separator.transform(u.file_stem().unwrap_or_default()));
|
||||
}
|
||||
_ => bail!("Unknown copy type: {}", opt.r#type),
|
||||
});
|
||||
};
|
||||
if it.peek().is_some() {
|
||||
s.push("\n");
|
||||
}
|
||||
|
|
@ -42,7 +52,7 @@ impl Actor for Copy {
|
|||
|
||||
// Copy the CWD path regardless even if the directory is empty
|
||||
if s.is_empty() && opt.r#type == "dirname" {
|
||||
s.push(opt.separator.transform(cx.cwd()));
|
||||
s.push(opt.separator.transform(&cx.cwd().os_str()));
|
||||
}
|
||||
|
||||
futures::executor::block_on(CLIPBOARD.set(s));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ impl Deref for Loc {
|
|||
fn deref(&self) -> &Self::Target { &self.inner }
|
||||
}
|
||||
|
||||
impl AsRef<Path> for Loc {
|
||||
fn as_ref(&self) -> &Path { &self.inner }
|
||||
}
|
||||
|
||||
impl PartialEq for Loc {
|
||||
fn eq(&self, other: &Self) -> bool { self.inner == other.inner }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ impl Url {
|
|||
}
|
||||
|
||||
Some(Self {
|
||||
loc: self.loc.strip_prefix(base.loc.as_path()).ok()?.into(),
|
||||
loc: self.loc.strip_prefix(&base.loc).ok()?.into(),
|
||||
scheme: self.scheme.clone(),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue