Skip to content

Commit 149a5fe

Browse files
committed
fix!: open command doesn't work under empty directories (#3226)
1 parent d8b0425 commit 149a5fe

File tree

45 files changed

+277
-280
lines changed

Some content is hidden

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

45 files changed

+277
-280
lines changed

Cargo.lock

Lines changed: 25 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ hashbrown = { version = "0.16.0", features = [ "serde" ] }
3535
indexmap = { version = "2.11.4", features = [ "serde" ] }
3636
libc = "0.2.176"
3737
lru = "0.16.1"
38-
mlua = { version = "0.11.3", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
38+
mlua = { version = "0.11.4", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
3939
objc = "0.2.7"
40-
ordered-float = { version = "5.0.0", features = [ "serde" ] }
40+
ordered-float = { version = "5.1.0", features = [ "serde" ] }
4141
parking_lot = "0.12.4"
4242
paste = "1.0.15"
4343
ratatui = { version = "0.29.0", features = [ "unstable-rendered-line-info", "unstable-widget-ref" ] }

yazi-actor/src/mgr/open.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use yazi_fs::File;
44
use yazi_macro::{act, succ};
55
use yazi_parser::mgr::{OpenDoOpt, OpenOpt};
66
use yazi_proxy::MgrProxy;
7-
use yazi_shared::{data::Data, url::UrlCow};
7+
use yazi_shared::data::Data;
88
use yazi_vfs::VfsFile;
99

1010
use crate::{Actor, Ctx, mgr::Quit};
@@ -17,27 +17,28 @@ impl Actor for Open {
1717
const NAME: &str = "open";
1818

1919
fn act(cx: &mut Ctx, mut opt: Self::Options) -> Result<Data> {
20-
act!(mgr:escape_visual, cx)?;
21-
22-
let Some(hovered) = cx.hovered().map(|h| h.url_owned()).map(UrlCow::from) else { succ!() };
23-
2420
if !opt.interactive && ARGS.chooser_file.is_some() {
2521
succ!(if !opt.targets.is_empty() {
2622
Quit::with_selected(opt.targets)
2723
} else if opt.hovered {
28-
Quit::with_selected([hovered])
24+
Quit::with_selected(cx.hovered().map(|h| &h.url))
2925
} else {
26+
act!(mgr:escape_visual, cx)?;
3027
Quit::with_selected(cx.tab().selected_or_hovered())
3128
});
3229
}
3330

3431
if opt.targets.is_empty() {
3532
opt.targets = if opt.hovered {
36-
vec![hovered.clone()]
33+
cx.hovered().map(|h| vec![h.url.clone().into()]).unwrap_or_default()
3734
} else {
35+
act!(mgr:escape_visual, cx)?;
3836
cx.tab().selected_or_hovered().cloned().map(Into::into).collect()
3937
};
4038
}
39+
if opt.targets.is_empty() {
40+
succ!();
41+
}
4142

4243
let todo: Vec<_> = opt
4344
.targets
@@ -49,7 +50,7 @@ impl Actor for Open {
4950

5051
let cwd = cx.cwd().clone();
5152
if todo.is_empty() {
52-
return act!(mgr:open_do, cx, OpenDoOpt { cwd, hovered, targets: opt.targets, interactive: opt.interactive });
53+
return act!(mgr:open_do, cx, OpenDoOpt { cwd, targets: opt.targets, interactive: opt.interactive });
5354
}
5455

5556
let scheduler = cx.tasks.scheduler.clone();
@@ -61,12 +62,7 @@ impl Actor for Open {
6162
}
6263
}
6364
if scheduler.fetch_mimetype(files).await {
64-
MgrProxy::open_do(OpenDoOpt {
65-
cwd,
66-
hovered,
67-
targets: opt.targets,
68-
interactive: opt.interactive,
69-
});
65+
MgrProxy::open_do(OpenDoOpt { cwd, targets: opt.targets, interactive: opt.interactive });
7066
}
7167
});
7268
succ!();

yazi-actor/src/mgr/open_do.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use yazi_config::{YAZI, popup::PickCfg};
55
use yazi_macro::succ;
66
use yazi_parser::mgr::OpenDoOpt;
77
use yazi_proxy::{PickProxy, TasksProxy};
8-
use yazi_shared::data::Data;
8+
use yazi_shared::{data::Data, url::UrlCow};
99

1010
use crate::{Actor, Ctx};
1111

@@ -30,7 +30,7 @@ impl Actor for OpenDo {
3030
if targets.is_empty() {
3131
succ!();
3232
} else if !opt.interactive {
33-
succ!(cx.tasks.process_from_files(opt.cwd, opt.hovered, targets));
33+
succ!(cx.tasks.process_with_selected(opt.cwd, targets));
3434
}
3535

3636
let openers: Vec<_> = YAZI.opener.all(YAZI.open.common(&targets).into_iter());
@@ -39,10 +39,10 @@ impl Actor for OpenDo {
3939
}
4040

4141
let pick = PickProxy::show(PickCfg::open(openers.iter().map(|o| o.desc()).collect()));
42-
let urls = [opt.hovered].into_iter().chain(targets.into_iter().map(|(u, _)| u)).collect();
42+
let urls = [UrlCow::default()].into_iter().chain(targets.into_iter().map(|(u, _)| u)).collect();
4343
tokio::spawn(async move {
4444
if let Ok(choice) = pick.await {
45-
TasksProxy::open_with(Cow::Borrowed(openers[choice]), opt.cwd, urls);
45+
TasksProxy::file_open(Cow::Borrowed(openers[choice]), opt.cwd, urls);
4646
}
4747
});
4848
succ!();

yazi-actor/src/mgr/quit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl Quit {
7777
s
7878
});
7979

80-
emit!(Quit(EventQuit { selected: Some(paths), ..Default::default() }));
80+
if !paths.is_empty() {
81+
emit!(Quit(EventQuit { selected: Some(paths), ..Default::default() }));
82+
}
8183
}
8284
}

yazi-actor/src/mgr/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Actor for SearchStop {
111111
succ!();
112112
}
113113

114-
let rep = tab.history.remove_or(&tab.cwd().to_regular());
114+
let rep = tab.history.remove_or(tab.cwd().to_regular());
115115
drop(mem::replace(&mut tab.current, rep));
116116

117117
act!(mgr:hidden, cx)?;

yazi-actor/src/mgr/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Actor for Shell {
3737
return;
3838
}
3939

40-
TasksProxy::open_with(
40+
TasksProxy::file_open(
4141
Cow::Owned(OpenerRule {
4242
run: opt.run.into_owned(),
4343
block: opt.block,

yazi-actor/src/tasks/open_with.rs renamed to yazi-actor/src/tasks/file_open.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use yazi_shared::data::Data;
55

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

8-
pub struct OpenWith;
8+
pub struct FileOpen;
99

10-
impl Actor for OpenWith {
10+
impl Actor for FileOpen {
1111
type Options = OpenWithOpt;
1212

13-
const NAME: &str = "open_with";
13+
const NAME: &str = "file_open";
1414

1515
fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> {
16-
succ!(cx.tasks.process_from_opener(
16+
succ!(cx.tasks.process_with_opener(
1717
opt.cwd,
1818
opt.opener,
1919
opt.targets.into_iter().map(|u| u.into_os_str2()).collect(),

yazi-actor/src/tasks/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
yazi_macro::mod_flat!(arrow cancel close inspect open_with process_exec show update_succeed);
1+
yazi_macro::mod_flat!(arrow cancel close file_open inspect process_open show update_succeed);

yazi-actor/src/tasks/process_exec.rs renamed to yazi-actor/src/tasks/process_open.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use anyhow::Result;
22
use yazi_macro::succ;
3-
use yazi_parser::tasks::ProcessExecOpt;
3+
use yazi_parser::tasks::ProcessOpenOpt;
44
use yazi_shared::data::Data;
55

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

8-
pub struct ProcessExec;
8+
pub struct ProcessOpen;
99

10-
impl Actor for ProcessExec {
11-
type Options = ProcessExecOpt;
10+
impl Actor for ProcessOpen {
11+
type Options = ProcessOpenOpt;
1212

13-
const NAME: &str = "process_exec";
13+
const NAME: &str = "process_open";
1414

1515
fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> {
1616
succ!(cx.tasks.scheduler.process_open(opt));

0 commit comments

Comments
 (0)