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 = [ "<Down>" ], exec = "arrow 1" },
{ on = [ "<Left>" ], exec = "leave" },
{ on = [ "<Right>" ], exec = "open" },
{ on = [ "<C-Right>" ], exec = "open --select" },
{ on = [ "<Right>" ], exec = "enter" },
{ on = [ "<Enter>" ], exec = "open" },
# Selection
{ on = [ "<Space>" ], exec = "select --state=none" },
@ -135,5 +135,8 @@ keymap = [
{ on = [ "y" ], exec = [ "yank" ] },
{ 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.
- undo: Undo the last operation.
- redo: Redo the last operation.
### Insert mode
- close: Cancel input.

View File

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

View File

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

View File

@ -262,16 +262,6 @@ impl Tab {
};
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 {

View File

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