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() {
|
fn test_split() {
|
||||||
yazi_fs::init();
|
yazi_fs::init();
|
||||||
compare("foo", "", "foo");
|
compare("foo", "", "foo");
|
||||||
compare("foo\\", "foo\\", "");
|
compare(r"foo\", r"foo\", "");
|
||||||
compare("foo\\bar", "foo\\", "bar");
|
compare(r"foo\bar", r"foo\", "bar");
|
||||||
compare("foo\\bar\\", "foo\\bar\\", "");
|
compare(r"foo\bar\", r"foo\bar\", "");
|
||||||
compare("C:\\", "C:\\", "");
|
compare(r"C:\", r"C:\", "");
|
||||||
compare("C:\\foo", "C:\\", "foo");
|
compare(r"C:\foo", r"C:\", "foo");
|
||||||
compare("C:\\foo\\", "C:\\foo\\", "");
|
compare(r"C:\foo\", r"C:\foo\", "");
|
||||||
compare("C:\\foo\\bar", "C:\\foo\\", "bar");
|
compare(r"C:\foo\bar", r"C:\foo\", "bar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
// FIXME: VFS
|
use std::ffi::OsString;
|
||||||
use std::{ffi::OsString, path::Path};
|
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use yazi_macro::{act, succ};
|
use yazi_macro::{act, succ};
|
||||||
|
|
@ -28,13 +27,24 @@ impl Actor for Copy {
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
while let Some(u) = it.next() {
|
while let Some(u) = it.next() {
|
||||||
s.push(match opt.r#type.as_ref() {
|
match opt.r#type.as_ref() {
|
||||||
"path" => opt.separator.transform(u),
|
// TODO: rename to "url"
|
||||||
"dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))),
|
"path" => {
|
||||||
"filename" => opt.separator.transform(u.name()),
|
s.push(opt.separator.transform(&u.os_str()));
|
||||||
"name_without_ext" => opt.separator.transform(u.file_stem().unwrap_or_default()),
|
}
|
||||||
|
"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),
|
_ => bail!("Unknown copy type: {}", opt.r#type),
|
||||||
});
|
};
|
||||||
if it.peek().is_some() {
|
if it.peek().is_some() {
|
||||||
s.push("\n");
|
s.push("\n");
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +52,7 @@ impl Actor for Copy {
|
||||||
|
|
||||||
// Copy the CWD path regardless even if the directory is empty
|
// Copy the CWD path regardless even if the directory is empty
|
||||||
if s.is_empty() && opt.r#type == "dirname" {
|
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));
|
futures::executor::block_on(CLIPBOARD.set(s));
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ impl Deref for Loc {
|
||||||
fn deref(&self) -> &Self::Target { &self.inner }
|
fn deref(&self) -> &Self::Target { &self.inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<Path> for Loc {
|
||||||
|
fn as_ref(&self) -> &Path { &self.inner }
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for Loc {
|
impl PartialEq for Loc {
|
||||||
fn eq(&self, other: &Self) -> bool { self.inner == other.inner }
|
fn eq(&self, other: &Self) -> bool { self.inner == other.inner }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ impl Url {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Self {
|
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(),
|
scheme: self.scheme.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue