diff --git a/src/core/event.rs b/src/core/event.rs index 78193f2c..0c50ef80 100644 --- a/src/core/event.rs +++ b/src/core/event.rs @@ -4,7 +4,7 @@ use anyhow::Result; use crossterm::event::KeyEvent; use tokio::sync::{mpsc::UnboundedSender, oneshot}; -use super::{files::FilesOp, input::InputOpt, manager::PreviewData, select::SelectOpt}; +use super::{files::{File, FilesOp}, input::InputOpt, manager::PreviewData, select::SelectOpt}; use crate::config::{keymap::{Control, KeymapLayer}, open::Opener}; static mut TX: Option> = None; @@ -24,7 +24,7 @@ pub enum Event { Files(FilesOp), Pages(usize), Mimetype(BTreeMap), - Hover, + Hover(Option), Preview(PathBuf, PreviewData), // Input @@ -88,6 +88,12 @@ macro_rules! emit { (Mimetype($mimes:expr)) => { $crate::core::Event::Mimetype($mimes).emit(); }; + (Hover) => { + $crate::core::Event::Hover(None).emit(); + }; + (Hover($file:expr)) => { + $crate::core::Event::Hover(Some($file)).emit(); + }; (Preview($path:expr, $data:expr)) => { $crate::core::Event::Preview($path, $data).emit(); }; diff --git a/src/core/manager/folder.rs b/src/core/manager/folder.rs index f72090f3..648fa2ff 100644 --- a/src/core/manager/folder.rs +++ b/src/core/manager/folder.rs @@ -146,19 +146,16 @@ impl Folder { } pub fn hover(&mut self, path: &Path) -> bool { - if matches!(self.hovered, Some(ref h) if h.path == path) { - return false; - } - let new = self.position(path).unwrap_or(self.cursor); if new > self.cursor { self.next(new - self.cursor) } else { self.prev(self.cursor - new) } } pub fn hover_force(&mut self, file: File) -> bool { - if !self.hover(&file.path) && self.files.is_empty() { - self.hovered = Some(file); + if self.hover(&file.path) { return true; } + + self.hovered = Some(file); false } } diff --git a/src/core/manager/manager.rs b/src/core/manager/manager.rs index b4632535..dba8db8c 100644 --- a/src/core/manager/manager.rs +++ b/src/core/manager/manager.rs @@ -1,5 +1,6 @@ use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, mem, path::PathBuf}; +use anyhow::Error; use tokio::fs; use super::{PreviewData, Tab, Tabs, Watcher}; @@ -179,13 +180,21 @@ impl Manager { if let Ok(name) = result.await { let path = cwd.join(&name); + let hovered = path.components().take(cwd.components().count() + 1).collect::(); + if name.ends_with('/') { - fs::create_dir_all(path).await.ok(); + fs::create_dir_all(path).await?; } else { fs::create_dir_all(path.parent().unwrap()).await.ok(); - fs::File::create(path).await.ok(); + fs::File::create(path).await?; + } + + if let Ok(file) = File::from(&hovered).await { + emit!(Hover(file)); + emit!(Refresh); } } + Ok::<(), Error>(()) }); false } diff --git a/src/ui/app.rs b/src/ui/app.rs index a4465906..c9b6b450 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -125,8 +125,10 @@ impl App { emit!(Render); } } - Event::Hover => { - if manager.preview() { + Event::Hover(file) => { + let mut b = file.map(|f| manager.current_mut().hover_force(f)).unwrap_or(false); + b |= manager.preview(); + if b { emit!(Render); } }