From 95dc0d6e380d494e81d0119876ea83a76e00f1f3 Mon Sep 17 00:00:00 2001 From: Lingxuan Ye Date: Wed, 15 Apr 2026 14:31:56 +0800 Subject: [PATCH] added drag column function --- yazi-actor/src/app/mouse.rs | 7 ++-- yazi-config/preset/yazi-default.toml | 2 +- yazi-plugin/preset/components/root.lua | 48 +++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/yazi-actor/src/app/mouse.rs b/yazi-actor/src/app/mouse.rs index c7717806..dc935fa4 100644 --- a/yazi-actor/src/app/mouse.rs +++ b/yazi-actor/src/app/mouse.rs @@ -5,7 +5,7 @@ use tracing::error; use yazi_actor::lives::Lives; use yazi_binding::runtime_scope; use yazi_config::YAZI; -use yazi_macro::succ; +use yazi_macro::{render, succ}; use yazi_parser::app::MouseForm; use yazi_plugin::LUA; use yazi_shared::data::Data; @@ -45,7 +45,10 @@ impl Actor for Mouse { MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?, MouseEventKind::Moved => root.call_method("move", event)?, - MouseEventKind::Drag(_) => root.call_method("drag", event)?, + MouseEventKind::Drag(_) => { + root.call_method::<()>("drag", event)?; + render!(); + } } Ok(()) diff --git a/yazi-config/preset/yazi-default.toml b/yazi-config/preset/yazi-default.toml index 8b486c16..f6566e5c 100644 --- a/yazi-config/preset/yazi-default.toml +++ b/yazi-config/preset/yazi-default.toml @@ -14,7 +14,7 @@ linemode = "none" show_hidden = false show_symlink = true scrolloff = 5 -mouse_events = [ "click", "scroll" ] +mouse_events = [ "click", "scroll", "drag" ] [preview] wrap = "no" diff --git a/yazi-plugin/preset/components/root.lua b/yazi-plugin/preset/components/root.lua index 67824985..5ffdbaec 100644 --- a/yazi-plugin/preset/components/root.lua +++ b/yazi-plugin/preset/components/root.lua @@ -1,6 +1,7 @@ Root = { _id = "root", _drag_start = ui.Rect {}, + _drag_which = nil, -- "left" or "right" when dragging a panel separator } function Root:new(area) @@ -53,6 +54,26 @@ function Root:click(event, up) if tostring(cx.layer) ~= "mgr" then return end + + if up then + Root._drag_which = nil + elseif event.is_left then + -- Check if clicking on a panel separator (Tab is self._children[3]) + local tab = self._children[3] + if tab and tab._chunks then + local c = tab._chunks + local lx = c[2].x - 1 -- left separator center x + local rx = c[3].x -- right separator center x + if c[1].w > 0 and event.x >= lx - 1 and event.x <= lx + 1 then + Root._drag_which = "left" + return + elseif c[3].w > 0 and event.x >= rx - 1 and event.x <= rx + 1 then + Root._drag_which = "right" + return + end + end + end + local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow()) return c and c:click(event, up) end @@ -75,4 +96,29 @@ end function Root:move(event) end -function Root:drag(event) end +function Root:drag(event) + if not Root._drag_which then + return + end + + local tab = self._children[3] + if not tab or not tab._chunks then + return + end + + local c = tab._chunks + local ratio = rt.mgr.ratio + + if Root._drag_which == "left" then + -- Dragging the left separator: adjust parent and current widths + local new_parent = math.max(1, event.x - c[1].x + 1) + local new_current = math.max(1, c[1].w + c[2].w - new_parent) + rt.mgr.ratio = { new_parent, new_current, c[3].w > 0 and c[3].w or 1 } + elseif Root._drag_which == "right" then + -- Dragging the right separator: adjust current and preview widths + local right_edge = c[3].x + c[3].w - 1 + local new_preview = math.max(1, right_edge - event.x) + local new_current = math.max(1, c[2].w + c[3].w - new_preview) + rt.mgr.ratio = { c[1].w > 0 and c[1].w or 1, new_current, new_preview } + end +end