-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·67 lines (57 loc) · 1.52 KB
/
main.lua
File metadata and controls
executable file
·67 lines (57 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- @since 25.4.8
--- @sync entry
--- Thanks to https://github.com/yazi-rs/plugins/blob/main/toggle-pane.yazi/main.lua for MIT license
local function mgr_emit(name, args)
if ya.emit then
ya.emit(name, args)
else
ya.mgr_emit(name, args)
end
end
local function entry(self, job)
if #job.args ~= 1 or (job.args[1] ~= "enter" and job.args[1] ~= "leave") then
return
end
local h = cx.active.current.hovered
local default = rt.mgr.ratio
local is_dir = h and h.cha.is_dir
self.parent = self.parent or default.parent
self.current = self.current or default.current
self.preview = self.preview or default.preview
local parent_is_hidden = 0 == self.parent
local current_is_hidden = 0 == self.current
if job.args[1] == "leave" then
if parent_is_hidden and current_is_hidden then
self.current = default.current
elseif parent_is_hidden then
self.parent = default.parent
else
mgr_emit("leave", {})
end
else
if is_dir then
mgr_emit("enter", {})
elseif not parent_is_hidden then
self.parent = 0
elseif not current_is_hidden then
self.current = 0
end
end
Tab.layout = function(tab_self)
local all = self.parent + self.current + self.preview
tab_self._chunks = ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(self.parent, all),
ui.Constraint.Ratio(self.current, all),
ui.Constraint.Ratio(self.preview, all),
})
:split(tab_self._area)
end
if ya.emit then
ya.emit("app:resize", {})
else
ya.app_emit("resize", {})
end
end
return { entry = entry }