Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow multiple hlgroups inside one column #240

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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