From 5d599167a19cf0eafbb6e7f51f0bf461678d12ac Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 17 Feb 2024 17:20:11 +0800 Subject: [PATCH] .. --- yazi-core/src/tab/commands/enter.rs | 39 +++-------------------------- yazi-core/src/tab/commands/leave.rs | 36 ++++---------------------- 2 files changed, 9 insertions(+), 66 deletions(-) diff --git a/yazi-core/src/tab/commands/enter.rs b/yazi-core/src/tab/commands/enter.rs index b01f4579..be527442 100644 --- a/yazi-core/src/tab/commands/enter.rs +++ b/yazi-core/src/tab/commands/enter.rs @@ -1,40 +1,9 @@ -use std::mem; +use yazi_shared::event::Cmd; -use yazi_shared::{event::Cmd, render}; - -use crate::{manager::Manager, tab::Tab}; - -pub struct Opt; -impl From<()> for Opt { - fn from(_: ()) -> Self { Self } -} -impl From for Opt { - fn from(_: Cmd) -> Self { Self } -} +use crate::tab::Tab; impl Tab { - pub fn enter(&mut self, _: impl Into) { - let Some(hovered) = self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()) else { - return; - }; - - // Current - let rep = self.history_new(&hovered); - let rep = mem::replace(&mut self.current, rep); - if rep.cwd.is_regular() { - self.history.insert(rep.cwd.clone(), rep); - } - - // Parent - if let Some(rep) = self.parent.take() { - self.history.insert(rep.cwd.clone(), rep); - } - self.parent = Some(self.history_new(&hovered.parent_url().unwrap())); - - // Backstack - self.backstack.push(hovered); - - Manager::_refresh(); - render!(); + pub fn enter(&mut self, _: Cmd) { + self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()).map(|u| self.cd(u)); } } diff --git a/yazi-core/src/tab/commands/leave.rs b/yazi-core/src/tab/commands/leave.rs index c98d4236..85d96fe6 100644 --- a/yazi-core/src/tab/commands/leave.rs +++ b/yazi-core/src/tab/commands/leave.rs @@ -1,8 +1,6 @@ -use std::mem; +use yazi_shared::event::Cmd; -use yazi_shared::{event::Cmd, render}; - -use crate::{manager::Manager, tab::Tab}; +use crate::tab::Tab; pub struct Opt; impl From<()> for Opt { @@ -14,36 +12,12 @@ impl From for Opt { impl Tab { pub fn leave(&mut self, _: impl Into) { - let current = self + self .current .hovered() .and_then(|h| h.parent()) .filter(|p| *p != self.current.cwd) - .or_else(|| self.current.cwd.parent_url()); - - let Some(current) = current else { - return; - }; - - // Parent - if let Some(rep) = self.parent.take() { - self.history.insert(rep.cwd.clone(), rep); - } - if let Some(parent) = current.parent_url() { - self.parent = Some(self.history_new(&parent)); - } - - // Current - let rep = self.history_new(¤t); - let rep = mem::replace(&mut self.current, rep); - if rep.cwd.is_regular() { - self.history.insert(rep.cwd.clone(), rep); - } - - // Backstack - self.backstack.push(current); - - Manager::_refresh(); - render!(); + .or_else(|| self.current.cwd.parent_url()) + .map(|u| self.cd(u)); } }