mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
added drag column function
This commit is contained in:
parent
4a2e5addcd
commit
95dc0d6e38
3 changed files with 53 additions and 4 deletions
|
|
@ -5,7 +5,7 @@ use tracing::error;
|
||||||
use yazi_actor::lives::Lives;
|
use yazi_actor::lives::Lives;
|
||||||
use yazi_binding::runtime_scope;
|
use yazi_binding::runtime_scope;
|
||||||
use yazi_config::YAZI;
|
use yazi_config::YAZI;
|
||||||
use yazi_macro::succ;
|
use yazi_macro::{render, succ};
|
||||||
use yazi_parser::app::MouseForm;
|
use yazi_parser::app::MouseForm;
|
||||||
use yazi_plugin::LUA;
|
use yazi_plugin::LUA;
|
||||||
use yazi_shared::data::Data;
|
use yazi_shared::data::Data;
|
||||||
|
|
@ -45,7 +45,10 @@ impl Actor for Mouse {
|
||||||
MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?,
|
MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?,
|
||||||
|
|
||||||
MouseEventKind::Moved => root.call_method("move", event)?,
|
MouseEventKind::Moved => root.call_method("move", event)?,
|
||||||
MouseEventKind::Drag(_) => root.call_method("drag", event)?,
|
MouseEventKind::Drag(_) => {
|
||||||
|
root.call_method::<()>("drag", event)?;
|
||||||
|
render!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ linemode = "none"
|
||||||
show_hidden = false
|
show_hidden = false
|
||||||
show_symlink = true
|
show_symlink = true
|
||||||
scrolloff = 5
|
scrolloff = 5
|
||||||
mouse_events = [ "click", "scroll" ]
|
mouse_events = [ "click", "scroll", "drag" ]
|
||||||
|
|
||||||
[preview]
|
[preview]
|
||||||
wrap = "no"
|
wrap = "no"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
Root = {
|
Root = {
|
||||||
_id = "root",
|
_id = "root",
|
||||||
_drag_start = ui.Rect {},
|
_drag_start = ui.Rect {},
|
||||||
|
_drag_which = nil, -- "left" or "right" when dragging a panel separator
|
||||||
}
|
}
|
||||||
|
|
||||||
function Root:new(area)
|
function Root:new(area)
|
||||||
|
|
@ -53,6 +54,26 @@ function Root:click(event, up)
|
||||||
if tostring(cx.layer) ~= "mgr" then
|
if tostring(cx.layer) ~= "mgr" then
|
||||||
return
|
return
|
||||||
end
|
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())
|
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
||||||
return c and c:click(event, up)
|
return c and c:click(event, up)
|
||||||
end
|
end
|
||||||
|
|
@ -75,4 +96,29 @@ end
|
||||||
|
|
||||||
function Root:move(event) 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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue