mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add option to enter directory on open command
This commit is contained in:
parent
1036685f91
commit
6f1677acf3
1 changed files with 14 additions and 6 deletions
|
|
@ -8,22 +8,31 @@ use yazi_shared::{emit, event::{EventQuit, Exec}, fs::{File, Url}, Layer, MIME_D
|
||||||
use crate::{manager::Manager, select::Select, tasks::Tasks};
|
use crate::{manager::Manager, select::Select, tasks::Tasks};
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
targets: Option<Vec<(Url, Option<String>)>>,
|
targets: Option<Vec<(Url, Option<String>)>>,
|
||||||
interactive: bool,
|
interactive: bool,
|
||||||
|
or_enter_dir: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Exec> for Opt {
|
impl From<&Exec> for Opt {
|
||||||
fn from(e: &Exec) -> Self {
|
fn from(e: &Exec) -> Self {
|
||||||
Self { targets: e.take_data(), interactive: e.named.contains_key("interactive") }
|
Self {
|
||||||
|
targets: e.take_data(),
|
||||||
|
interactive: e.named.contains_key("interactive"),
|
||||||
|
or_enter_dir: e.named.contains_key("or-enter-dir")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Manager {
|
impl Manager {
|
||||||
pub fn open(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
|
pub fn open(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
|
||||||
|
let mut opt = opt.into() as Opt;
|
||||||
let selected = self.selected();
|
let selected = self.selected();
|
||||||
if selected.is_empty() {
|
|
||||||
|
if selected.is_empty() || Self::quit_with_selected(&selected) {
|
||||||
return;
|
return;
|
||||||
} else if Self::quit_with_selected(&selected) {
|
} else if opt.or_enter_dir && selected.len() == 1 && selected[0].is_dir() {
|
||||||
|
let cur_tab = &mut self.tabs.items[self.tabs.idx];
|
||||||
|
cur_tab.enter(());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +47,6 @@ impl Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut opt = opt.into() as Opt;
|
|
||||||
if todo.is_empty() {
|
if todo.is_empty() {
|
||||||
opt.targets = Some(done);
|
opt.targets = Some(done);
|
||||||
return self.open_do(opt, tasks);
|
return self.open_do(opt, tasks);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue