forked from akinsho/bufferline.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.lua
More file actions
47 lines (40 loc) · 1.25 KB
/
Copy pathstate.lua
File metadata and controls
47 lines (40 loc) · 1.25 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
local M = {}
local lazy = require("bufferline.lazy")
local utils = lazy.require("bufferline.utils") ---@module "bufferline.utils"
-----------------------------------------------------------------------------//
-- State
-----------------------------------------------------------------------------//
---@type bufferline.State
local state = {
is_picking = false,
hovered = nil,
custom_sort = nil,
current_element_index = nil,
components = {},
__components = {},
visible_components = {},
left_offset_size = 0,
right_offset_size = 0,
}
---@param list bufferline.Component[]
---@return bufferline.Component[]
local function filter_invisible(list)
return utils.fold(function(accum, item)
if item.focusable ~= false and not item.hidden then table.insert(accum, item) end
return accum
end, list, {})
end
local component_keys = { "components", "visible_components" }
---@param new_state bufferline.State
function M.set(new_state)
for key, value in pairs(new_state) do
if value == vim.NIL then value = nil end
if vim.tbl_contains(component_keys, key) then
value = filter_invisible(value --[=[@as bufferline.Component[]]=])
end
state[key] = value
end
end
return setmetatable(M, {
__index = function(_, k) return state[k] end,
})