From 1a1da216ca2d8117dbdcdc497b8d96fa4caf00d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sat, 29 Jun 2024 11:25:45 +0800 Subject: [PATCH] feat: support right-click to open files (#1232) --- yazi-cli/src/args.rs | 2 +- yazi-dds/src/lib.rs | 3 +++ yazi-plugin/preset/components/current.lua | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index 22ed257b..e18f6a99 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -45,7 +45,7 @@ impl CommandPub { pub(super) fn receiver(&self) -> Result { if let Some(receiver) = self.receiver { Ok(receiver) - } else if let Ok(s) = std::env::var("YAZI_ID") { + } else if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) { Ok(s.parse()?) } else { bail!("No receiver ID provided, also no YAZI_ID environment variable found.") diff --git a/yazi-dds/src/lib.rs b/yazi-dds/src/lib.rs index b837cdd6..6a50bcde 100644 --- a/yazi-dds/src/lib.rs +++ b/yazi-dds/src/lib.rs @@ -42,6 +42,9 @@ pub fn init() { USERS_CACHE.with(Default::default); // Env + if let Some(s) = std::env::var("YAZI_ID").ok().filter(|s| !s.is_empty()) { + std::env::set_var("YAZI_PID", s); + } std::env::set_var("YAZI_ID", ID.to_string()); std::env::set_var( "YAZI_LEVEL", diff --git a/yazi-plugin/preset/components/current.lua b/yazi-plugin/preset/components/current.lua index fa57e79e..839fed8f 100644 --- a/yazi-plugin/preset/components/current.lua +++ b/yazi-plugin/preset/components/current.lua @@ -44,13 +44,18 @@ function Current:render(area) end function Current:click(event, up) - if up or not event.is_left then + if up or event.is_middle then return end local f = Folder:by_kind(Folder.CURRENT) - if event.y <= #f.window and f.hovered then - ya.manager_emit("arrow", { event.y + f.offset - f.hovered.idx }) + if event.y > #f.window or not f.hovered then + return + end + + ya.manager_emit("arrow", { event.y + f.offset - f.hovered.idx }) + if event.is_right then + ya.manager_emit("open", { hovered = true }) end end