diff --git a/yazi-plugin/preset/components/folder.lua b/yazi-plugin/preset/components/folder.lua index 4ee28af0..3cf687ad 100644 --- a/yazi-plugin/preset/components/folder.lua +++ b/yazi-plugin/preset/components/folder.lua @@ -69,30 +69,31 @@ function Folder:linemode(area) end function Folder:markers(area, markers) - if #markers == 0 then + if #markers == 0 or area.w * area.h == 0 then return {} end local elements = {} local append = function(last) - local p = ui.Bar( + local y = math.min(area.y + last[1], area.y + area.h) - 1 + local bar = ui.Bar( ui.Rect { - x = math.max(1, area.x) - 1, - y = area.y + last[1] - 1, + x = math.max(0, area.x - 1), + y = y, w = 1, - h = 1 + last[2] - last[1], + h = 1 + math.min(last[2] - last[1], area.h - y), }, ui.Position.LEFT ) if last[3] == 1 then - p = p:style(THEME.manager.marker_copied) + bar = bar:style(THEME.manager.marker_copied) elseif last[3] == 2 then - p = p:style(THEME.manager.marker_cut) + bar = bar:style(THEME.manager.marker_cut) elseif last[3] == 3 then - p = p:style(THEME.manager.marker_selected) + bar = bar:style(THEME.manager.marker_selected) end - elements[#elements + 1] = p + elements[#elements + 1] = bar end local last = { markers[1][1], markers[1][1], markers[1][2] } -- start, end, type @@ -153,7 +154,7 @@ function Folder:current(area) markers[#markers + 1] = { i, 3 } end end - return utils.flat { ui.List(area, items), self:linemode(area), table.unpack(self:markers(area, markers)) } + return utils.flat { ui.List(area, items), self:linemode(area), self:markers(area, markers) } end function Folder:preview(area) diff --git a/yazi-plugin/preset/utils.lua b/yazi-plugin/preset/utils.lua index 05872313..7f5121c0 100644 --- a/yazi-plugin/preset/utils.lua +++ b/yazi-plugin/preset/utils.lua @@ -2,6 +2,16 @@ table.unpack = table.unpack or unpack utils = utils or {} +function utils.clamp(min, x, max) + if x < min then + return min + elseif x > max then + return max + else + return x + end +end + function utils.flat(t) local r = {} for _, v in ipairs(t) do