feat: fallback to the enter behavior when there is only one item selected and its a directory #2

This commit is contained in:
sxyazi 2023-07-23 00:14:55 +08:00
parent 14639f64ac
commit 43e731b9a1
No known key found for this signature in database
6 changed files with 17 additions and 22 deletions

View file

@ -21,8 +21,8 @@ keymap = [
{ on = [ "<Up>" ], exec = "arrow -1" }, { on = [ "<Up>" ], exec = "arrow -1" },
{ on = [ "<Down>" ], exec = "arrow 1" }, { on = [ "<Down>" ], exec = "arrow 1" },
{ on = [ "<Left>" ], exec = "leave" }, { on = [ "<Left>" ], exec = "leave" },
{ on = [ "<Right>" ], exec = "open" }, { on = [ "<Right>" ], exec = "enter" },
{ on = [ "<C-Right>" ], exec = "open --select" }, { on = [ "<Enter>" ], exec = "open" },
# Selection # Selection
{ on = [ "<Space>" ], exec = "select --state=none" }, { on = [ "<Space>" ], exec = "select --state=none" },
@ -135,5 +135,8 @@ keymap = [
{ on = [ "y" ], exec = [ "yank" ] }, { on = [ "y" ], exec = [ "yank" ] },
{ on = [ "p" ], exec = [ "paste" ] }, { on = [ "p" ], exec = [ "paste" ] },
{ on = [ "P" ], exec = [ "paste --before" ] } { on = [ "P" ], exec = [ "paste --before" ] },
{ on = [ "u" ], exec = [ "undo" ] },
{ on = [ "<C-r>" ], exec = [ "redo" ] },
] ]

View file

@ -145,6 +145,9 @@
- `--before`: Paste the copied characters before the cursor. - `--before`: Paste the copied characters before the cursor.
- undo: Undo the last operation.
- redo: Redo the last operation.
### Insert mode ### Insert mode
- close: Cancel input. - close: Cancel input.

View file

@ -1,4 +1,4 @@
use super::{InputMode, InputSnap}; use super::InputSnap;
#[derive(Default, PartialEq, Eq)] #[derive(Default, PartialEq, Eq)]
pub(super) struct InputSnaps { pub(super) struct InputSnaps {

View file

@ -113,8 +113,12 @@ impl Manager {
} }
pub fn open(&mut self, select: bool) -> bool { pub fn open(&mut self, select: bool) -> bool {
let mut files = self let files = self.selected();
.selected() if files.len() == 1 && files[0].meta.is_dir() {
return self.active_mut().enter();
}
let mut files = files
.into_iter() .into_iter()
.filter(|f| f.meta.is_file()) .filter(|f| f.meta.is_file())
.map(|f| (f.path(), self.mimetype.get(&f.path).cloned())) .map(|f| (f.path(), self.mimetype.get(&f.path).cloned()))

View file

@ -262,16 +262,6 @@ impl Tab {
}; };
true true
} }
pub fn current_is_dir(&self) -> bool{
let hovered = if let Some(ref h) = self.current.hovered {
h.clone()
} else {
return false;
};
hovered.meta.is_dir()
}
} }
impl Tab { impl Tab {

View file

@ -78,12 +78,7 @@ impl Executor {
} }
// Operation // Operation
"open" => { "open" => cx.manager.open(exec.named.contains_key("select")),
if cx.manager.active().current_is_dir() {
return cx.manager.active_mut().enter();
}
cx.manager.open(exec.named.contains_key("select"))
},
"yank" => cx.manager.yank(exec.named.contains_key("cut")), "yank" => cx.manager.yank(exec.named.contains_key("cut")),
"paste" => { "paste" => {
let dest = cx.manager.current().cwd.clone(); let dest = cx.manager.current().cwd.clone();