Skip to content

Commit 4b56e73

Browse files
authored
feat: dynamic paths (#3316)
1 parent cc8f9a7 commit 4b56e73

File tree

42 files changed

+385
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+385
-218
lines changed

yazi-actor/src/lives/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl UserData for File {
7777
yazi_binding::impl_file_methods!(methods);
7878

7979
methods.add_method("size", |_, me, ()| {
80-
Ok(if me.is_dir() { me.folder.files.sizes.get(me.urn()).copied() } else { Some(me.len) })
80+
Ok(if me.is_dir() { me.folder.files.sizes.get(&me.urn()).copied() } else { Some(me.len) })
8181
});
8282
methods.add_method("mime", |lua, me, ()| {
8383
lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| {

yazi-actor/src/mgr/cd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use yazi_fs::{File, FilesOp, path::expand_url};
99
use yazi_macro::{act, err, render, succ};
1010
use yazi_parser::mgr::CdOpt;
1111
use yazi_proxy::{CmpProxy, InputProxy, MgrProxy};
12-
use yazi_shared::{Debounce, data::Data, errors::InputError, url::{AsUrl, UrlBuf, UrlLike}};
12+
use yazi_shared::{Debounce, data::Data, errors::InputError, path::PathLike, url::{AsUrl, UrlBuf, UrlLike}};
1313
use yazi_vfs::VfsFile;
1414

1515
use crate::{Actor, Ctx};
@@ -85,7 +85,7 @@ impl Cd {
8585
}
8686

8787
if let Some(p) = url.parent() {
88-
FilesOp::Upserting(p.into(), [(url.urn().to_owned(), file)].into()).emit();
88+
FilesOp::Upserting(p.into(), [(url.urn().owned(), file)].into()).emit();
8989
}
9090
MgrProxy::reveal(&url);
9191
}

yazi-actor/src/mgr/create.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use yazi_fs::{File, FilesOp};
44
use yazi_macro::{ok_or_not_found, succ};
55
use yazi_parser::mgr::CreateOpt;
66
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy};
7-
use yazi_shared::{data::Data, url::{UrlBuf, UrlLike}};
7+
use yazi_shared::{data::Data, path::PathLike, url::{UrlBuf, UrlLike}};
88
use yazi_vfs::{VfsFile, maybe_exists, provider};
99
use yazi_watcher::WATCHER;
1010

@@ -51,7 +51,7 @@ impl Create {
5151
&& let Some((parent, urn)) = real.pair()
5252
{
5353
ok_or_not_found!(provider::remove_file(&new).await);
54-
FilesOp::Deleting(parent.into(), [urn.to_owned()].into()).emit();
54+
FilesOp::Deleting(parent.into(), [urn.owned()].into()).emit();
5555
provider::create(&new).await?;
5656
} else if let Some(parent) = new.parent() {
5757
provider::create_dir_all(parent).await.ok();
@@ -65,7 +65,7 @@ impl Create {
6565
&& let Some((parent, urn)) = real.pair()
6666
{
6767
let file = File::new(&real).await?;
68-
FilesOp::Upserting(parent.into(), [(urn.to_owned(), file)].into()).emit();
68+
FilesOp::Upserting(parent.into(), [(urn.owned(), file)].into()).emit();
6969
MgrProxy::reveal(&real);
7070
}
7171

yazi-actor/src/mgr/filter_do.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use yazi_fs::Filter;
33
use yazi_macro::{act, render, succ};
44
use yazi_parser::mgr::FilterOpt;
5-
use yazi_shared::data::Data;
5+
use yazi_shared::{data::Data, path::PathLike};
66

77
use crate::{Actor, Ctx};
88

@@ -16,10 +16,10 @@ impl Actor for FilterDo {
1616
fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> {
1717
let filter = if opt.query.is_empty() { None } else { Some(Filter::new(&opt.query, opt.case)?) };
1818

19-
let hovered = cx.hovered().map(|f| f.urn().to_owned());
19+
let hovered = cx.hovered().map(|f| f.urn().owned());
2020
cx.current_mut().files.set_filter(filter);
2121

22-
if cx.hovered().map(|f| f.urn()) != hovered.as_deref() {
22+
if cx.hovered().map(|f| f.urn()) != hovered.as_ref().map(Into::into) {
2323
act!(mgr:hover, cx, hovered)?;
2424
act!(mgr:peek, cx)?;
2525
act!(mgr:watch, cx)?;

yazi-actor/src/mgr/hidden.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use yazi_core::tab::Folder;
33
use yazi_fs::FolderStage;
44
use yazi_macro::{act, render, render_and, succ};
55
use yazi_parser::mgr::HiddenOpt;
6-
use yazi_shared::data::Data;
6+
use yazi_shared::{data::Data, path::PathLike};
77

88
use crate::{Actor, Ctx};
99

@@ -18,7 +18,7 @@ impl Actor for Hidden {
1818
let state = opt.state.bool(cx.tab().pref.show_hidden);
1919
cx.tab_mut().pref.show_hidden = state;
2020

21-
let hovered = cx.hovered().map(|f| f.urn().to_owned());
21+
let hovered = cx.hovered().map(|f| f.urn().owned());
2222
let apply = |f: &mut Folder| {
2323
if f.stage == FolderStage::Loading {
2424
render!();
@@ -43,7 +43,7 @@ impl Actor for Hidden {
4343
{
4444
render!(h.repos(None));
4545
act!(mgr:peek, cx, true)?;
46-
} else if hovered.as_deref() != cx.hovered().map(|f| f.urn()) {
46+
} else if cx.hovered().map(|f| f.urn()) != hovered.as_ref().map(Into::into) {
4747
act!(mgr:peek, cx)?;
4848
act!(mgr:watch, cx)?;
4949
}

yazi-actor/src/mgr/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Actor for Hover {
2222
}
2323

2424
// Repos CWD
25-
tab.current.repos(opt.urn.as_deref());
25+
tab.current.repos(opt.urn.as_ref().map(Into::into));
2626

2727
// Turn on tracing
2828
if let (Some(h), Some(u)) = (tab.hovered(), opt.urn)

yazi-actor/src/mgr/rename.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use yazi_fs::{File, FilesOp};
55
use yazi_macro::{act, err, ok_or_not_found, succ};
66
use yazi_parser::mgr::RenameOpt;
77
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy};
8-
use yazi_shared::{Id, data::Data, url::{UrlBuf, UrlLike}};
8+
use yazi_shared::{Id, data::Data, path::PathLike, url::{UrlBuf, UrlLike}};
99
use yazi_vfs::{VfsFile, maybe_exists, provider};
1010
use yazi_watcher::WATCHER;
1111

@@ -73,18 +73,18 @@ impl Rename {
7373
&& let Some((parent, urn)) = u.pair()
7474
{
7575
ok_or_not_found!(provider::rename(&u, &new).await);
76-
FilesOp::Deleting(parent.to_owned(), [urn.to_owned()].into()).emit();
76+
FilesOp::Deleting(parent.to_owned(), [urn.owned()].into()).emit();
7777
}
7878

7979
let new = provider::casefold(&new).await?;
8080
let Some((new_p, new_n)) = new.pair() else { return Ok(()) };
8181

8282
let file = File::new(&new).await?;
8383
if new_p == old_p {
84-
FilesOp::Upserting(old_p.into(), [(old_n.to_owned(), file)].into()).emit();
84+
FilesOp::Upserting(old_p.into(), [(old_n.owned(), file)].into()).emit();
8585
} else {
86-
FilesOp::Deleting(old_p.into(), [old_n.to_owned()].into()).emit();
87-
FilesOp::Upserting(new_p.into(), [(new_n.to_owned(), file)].into()).emit();
86+
FilesOp::Deleting(old_p.into(), [old_n.owned()].into()).emit();
87+
FilesOp::Upserting(new_p.into(), [(new_n.owned(), file)].into()).emit();
8888
}
8989

9090
MgrProxy::reveal(&new);

yazi-actor/src/mgr/reveal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use yazi_fs::{File, FilesOp};
33
use yazi_macro::{act, render, succ};
44
use yazi_parser::mgr::RevealOpt;
5-
use yazi_shared::{data::Data, url::UrlLike};
5+
use yazi_shared::{data::Data, path::PathLike, url::UrlLike};
66

77
use crate::{Actor, Ctx};
88

@@ -31,7 +31,7 @@ impl Actor for Reveal {
3131
}
3232

3333
// Now, we can safely hover on the target
34-
act!(mgr:hover, cx, Some(child.to_owned()))?;
34+
act!(mgr:hover, cx, Some(child.owned()))?;
3535

3636
act!(mgr:peek, cx)?;
3737
act!(mgr:watch, cx)?;

yazi-actor/src/mgr/sort.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use yazi_core::tab::Folder;
33
use yazi_fs::{FilesSorter, FolderStage};
44
use yazi_macro::{act, render, render_and, succ};
55
use yazi_parser::mgr::SortOpt;
6-
use yazi_shared::data::Data;
6+
use yazi_shared::{data::Data, path::PathLike};
77

88
use crate::{Actor, Ctx};
99

@@ -23,7 +23,7 @@ impl Actor for Sort {
2323
pref.sort_translit = opt.translit.unwrap_or(pref.sort_translit);
2424

2525
let sorter = FilesSorter::from(&*pref);
26-
let hovered = cx.hovered().map(|f| f.urn().to_owned());
26+
let hovered = cx.hovered().map(|f| f.urn().owned());
2727
let apply = |f: &mut Folder| {
2828
if f.stage == FolderStage::Loading {
2929
render!();
@@ -49,7 +49,7 @@ impl Actor for Sort {
4949
{
5050
render!(h.repos(None));
5151
act!(mgr:peek, cx, true)?;
52-
} else if hovered.as_deref() != cx.hovered().map(|f| f.urn()) {
52+
} else if cx.hovered().map(|f| f.urn()) != hovered.as_ref().map(Into::into) {
5353
act!(mgr:peek, cx)?;
5454
act!(mgr:watch, cx)?;
5555
}

yazi-actor/src/mgr/update_files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl UpdateFiles {
5757
let tab = cx.tab_mut();
5858

5959
let urn = tab.current.url.urn();
60-
let leave = matches!(op, FilesOp::Deleting(_, ref urns) if urns.contains(urn));
60+
let leave = matches!(op, FilesOp::Deleting(_, ref urns) if urns.contains(&urn));
6161

6262
if let Some(f) = tab.parent.as_mut() {
6363
render!(f.update_pub(tab.id, op));
@@ -102,7 +102,7 @@ impl UpdateFiles {
102102
fn update_history(cx: &mut Ctx, op: FilesOp) -> Result<Data> {
103103
let tab = &mut cx.tab_mut();
104104
let leave = tab.parent.as_ref().and_then(|f| f.url.parent().map(|p| (p, f.url.urn()))).is_some_and(
105-
|(p, n)| matches!(op, FilesOp::Deleting(ref parent, ref urns) if *parent == p && urns.contains(n)),
105+
|(p, n)| matches!(op, FilesOp::Deleting(ref parent, ref urns) if *parent == p && urns.contains(&n)),
106106
);
107107

108108
tab

0 commit comments

Comments
 (0)