From cad0e061eb4ee7988ce67781fe1e7f7f18adeaf7 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 17 Feb 2024 18:00:52 +0800 Subject: [PATCH] .. --- yazi-config/preset/keymap.toml | 4 ++-- yazi-core/src/tab/commands/back.rs | 7 +++++++ yazi-core/src/tab/commands/backstack.rs | 25 ------------------------- yazi-core/src/tab/commands/cd.rs | 4 ++++ yazi-core/src/tab/commands/forward.rs | 7 +++++++ yazi-core/src/tab/commands/mod.rs | 3 ++- 6 files changed, 22 insertions(+), 28 deletions(-) create mode 100644 yazi-core/src/tab/commands/back.rs delete mode 100644 yazi-core/src/tab/commands/backstack.rs create mode 100644 yazi-core/src/tab/commands/forward.rs diff --git a/yazi-config/preset/keymap.toml b/yazi-config/preset/keymap.toml index f90d4d89..fba119b2 100644 --- a/yazi-config/preset/keymap.toml +++ b/yazi-config/preset/keymap.toml @@ -31,8 +31,8 @@ keymap = [ { on = [ "" ], exec = "arrow -100%", desc = "Move cursor up one page" }, { on = [ "" ], exec = "arrow 100%", desc = "Move cursor down one page" }, - { on = [ "h" ], exec = [ "escape --visual", "leave" ], desc = "Go back to the parent directory" }, - { on = [ "l" ], exec = [ "escape --visual", "enter" ], desc = "Enter the child directory" }, + { on = [ "h" ], exec = "leave", desc = "Go back to the parent directory" }, + { on = [ "l" ], exec = "enter", desc = "Enter the child directory" }, { on = [ "H" ], exec = "back", desc = "Go back to the previous directory" }, { on = [ "L" ], exec = "forward", desc = "Go forward to the next directory" }, diff --git a/yazi-core/src/tab/commands/back.rs b/yazi-core/src/tab/commands/back.rs new file mode 100644 index 00000000..3aec0be2 --- /dev/null +++ b/yazi-core/src/tab/commands/back.rs @@ -0,0 +1,7 @@ +use yazi_shared::event::Cmd; + +use crate::tab::Tab; + +impl Tab { + pub fn back(&mut self, _: Cmd) { self.backstack.shift_backward().cloned().map(|u| self.cd(u)); } +} diff --git a/yazi-core/src/tab/commands/backstack.rs b/yazi-core/src/tab/commands/backstack.rs deleted file mode 100644 index 8456233d..00000000 --- a/yazi-core/src/tab/commands/backstack.rs +++ /dev/null @@ -1,25 +0,0 @@ -use yazi_shared::event::Cmd; - -use crate::tab::Tab; - -pub struct Opt; -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} -impl From for Opt { - fn from(_: Cmd) -> Self { Self } -} - -impl Tab { - pub fn back(&mut self, _: impl Into) { - if let Some(url) = self.backstack.shift_backward().cloned() { - self.cd(url); - } - } - - pub fn forward(&mut self, _: impl Into) { - if let Some(url) = self.backstack.shift_forward().cloned() { - self.cd(url); - } - } -} diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index f563def7..8f0a4aad 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -33,6 +33,10 @@ impl Tab { } pub fn cd(&mut self, opt: impl Into) { + if !self.try_escape_visual() { + return; + } + let opt = opt.into() as Opt; if opt.interactive { return self.cd_interactive(); diff --git a/yazi-core/src/tab/commands/forward.rs b/yazi-core/src/tab/commands/forward.rs new file mode 100644 index 00000000..87bc5057 --- /dev/null +++ b/yazi-core/src/tab/commands/forward.rs @@ -0,0 +1,7 @@ +use yazi_shared::event::Cmd; + +use crate::tab::Tab; + +impl Tab { + pub fn forward(&mut self, _: Cmd) { self.backstack.shift_forward().cloned().map(|u| self.cd(u)); } +} diff --git a/yazi-core/src/tab/commands/mod.rs b/yazi-core/src/tab/commands/mod.rs index 0f6801e0..8f0c6467 100644 --- a/yazi-core/src/tab/commands/mod.rs +++ b/yazi-core/src/tab/commands/mod.rs @@ -1,11 +1,12 @@ mod arrow; -mod backstack; +mod back; mod cd; mod copy; mod enter; mod escape; mod filter; mod find; +mod forward; mod hidden; mod jump; mod leave;