diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 72e87fc8..747f9e31 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -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 diff --git a/lua/oil/util.lua b/lua/oil/util.lua index 027b5db8..dc12d7f5 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -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