Skip to content

Commit

Permalink
feat: allow multiple hlgroups inside one column (#240)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Bekaboo and stevearc authored Dec 8, 2023
1 parent cd0c2d1 commit a173b57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions lua/oil/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,30 @@ 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
text = M.rpad(text, col_width[i])
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
Expand Down

0 comments on commit a173b57

Please sign in to comment.