feat: allow multiple hlgroups inside one column (#240)
* feat: allow multiple hlgroups inside one column * types: refactor formatting of highlight types * types: LuaLS can't infer type information from unpack --------- Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com>
This commit is contained in:
parent
cd0c2d1f0a
commit
a173b5776c
2 changed files with 21 additions and 3 deletions
|
|
@ -7,7 +7,10 @@ local M = {}
|
|||
---@field parsed_name nil|string
|
||||
|
||||
---@alias oil.EntryType "file"|"directory"|"socket"|"link"|"fifo"
|
||||
---@alias oil.TextChunk string|string[]
|
||||
---@alias oil.HlRange { [1]: string, [2]: integer, [3]: integer } A tuple of highlight group name, col_start, col_end
|
||||
---@alias oil.HlTuple { [1]: string, [2]: string } A tuple of text, highlight group
|
||||
---@alias oil.HlRangeTuple { [1]: string, [2]: oil.HlRange[] } A tuple of text, internal highlights
|
||||
---@alias oil.TextChunk string|oil.HlTuple|oil.HlRangeTuple
|
||||
---@alias oil.CrossAdapterAction "copy"|"move"
|
||||
|
||||
---@class (exact) oil.Adapter
|
||||
|
|
|
|||
|
|
@ -294,7 +294,8 @@ M.render_table = function(lines, col_width)
|
|||
for i, chunk in ipairs(cols) do
|
||||
local text, hl
|
||||
if type(chunk) == "table" then
|
||||
text, hl = unpack(chunk)
|
||||
text = chunk[1]
|
||||
hl = chunk[2]
|
||||
else
|
||||
text = chunk
|
||||
end
|
||||
|
|
@ -302,7 +303,21 @@ M.render_table = function(lines, col_width)
|
|||
table.insert(pieces, text)
|
||||
local col_end = col + text:len() + 1
|
||||
if hl then
|
||||
table.insert(highlights, { hl, #str_lines, col, col_end })
|
||||
if type(hl) == "table" then
|
||||
-- hl has the form { [1]: hl_name, [2]: col_start, [3]: col_end }[]
|
||||
-- Notice that col_start and col_end are relative position inside
|
||||
-- that col, so we need to add the offset to them
|
||||
for _, sub_hl in ipairs(hl) do
|
||||
table.insert(highlights, {
|
||||
sub_hl[1],
|
||||
#str_lines,
|
||||
col + sub_hl[2],
|
||||
col + sub_hl[3],
|
||||
})
|
||||
end
|
||||
else
|
||||
table.insert(highlights, { hl, #str_lines, col, col_end })
|
||||
end
|
||||
end
|
||||
col = col_end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue