feat: add support for bufnr in column rendering functions (#575)
This is primarily for user-defined custom columns, which may want access to the current path or similar information
This commit is contained in:
parent
abbfbd0dbc
commit
8abc58b038
2 changed files with 5 additions and 4 deletions
|
|
@ -12,7 +12,7 @@ local all_columns = {}
|
||||||
---@alias oil.ColumnSpec string|{[1]: string, [string]: any}
|
---@alias oil.ColumnSpec string|{[1]: string, [string]: any}
|
||||||
|
|
||||||
---@class (exact) oil.ColumnDefinition
|
---@class (exact) oil.ColumnDefinition
|
||||||
---@field render fun(entry: oil.InternalEntry, conf: nil|table): nil|oil.TextChunk
|
---@field render fun(entry: oil.InternalEntry, conf: nil|table, bufnr: integer): nil|oil.TextChunk
|
||||||
---@field parse fun(line: string, conf: nil|table): nil|string, nil|string
|
---@field parse fun(line: string, conf: nil|table): nil|string, nil|string
|
||||||
---@field compare? fun(entry: oil.InternalEntry, parsed_value: any): boolean
|
---@field compare? fun(entry: oil.InternalEntry, parsed_value: any): boolean
|
||||||
---@field render_action? fun(action: oil.ChangeAction): string
|
---@field render_action? fun(action: oil.ChangeAction): string
|
||||||
|
|
@ -60,8 +60,9 @@ M.EMPTY = EMPTY
|
||||||
---@param adapter oil.Adapter
|
---@param adapter oil.Adapter
|
||||||
---@param col_def oil.ColumnSpec
|
---@param col_def oil.ColumnSpec
|
||||||
---@param entry oil.InternalEntry
|
---@param entry oil.InternalEntry
|
||||||
|
---@param bufnr integer
|
||||||
---@return oil.TextChunk
|
---@return oil.TextChunk
|
||||||
M.render_col = function(adapter, col_def, entry)
|
M.render_col = function(adapter, col_def, entry, bufnr)
|
||||||
local name, conf = util.split_config(col_def)
|
local name, conf = util.split_config(col_def)
|
||||||
local column = M.get_column(adapter, name)
|
local column = M.get_column(adapter, name)
|
||||||
if not column then
|
if not column then
|
||||||
|
|
@ -69,7 +70,7 @@ M.render_col = function(adapter, col_def, entry)
|
||||||
return EMPTY
|
return EMPTY
|
||||||
end
|
end
|
||||||
|
|
||||||
local chunk = column.render(entry, conf)
|
local chunk = column.render(entry, conf, bufnr)
|
||||||
if type(chunk) == "table" then
|
if type(chunk) == "table" then
|
||||||
if chunk[1]:match("^%s*$") then
|
if chunk[1]:match("^%s*$") then
|
||||||
return EMPTY
|
return EMPTY
|
||||||
|
|
|
||||||
|
|
@ -747,7 +747,7 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter, is_hidden
|
||||||
table.insert(cols, id_key)
|
table.insert(cols, id_key)
|
||||||
-- Then add all the configured columns
|
-- Then add all the configured columns
|
||||||
for i, column in ipairs(column_defs) do
|
for i, column in ipairs(column_defs) do
|
||||||
local chunk = columns.render_col(adapter, column, entry)
|
local chunk = columns.render_col(adapter, column, entry, bufnr)
|
||||||
local text = type(chunk) == "table" and chunk[1] or chunk
|
local text = type(chunk) == "table" and chunk[1] or chunk
|
||||||
---@cast text string
|
---@cast text string
|
||||||
col_width[i + 1] = math.max(col_width[i + 1], vim.api.nvim_strwidth(text))
|
col_width[i + 1] = math.max(col_width[i + 1], vim.api.nvim_strwidth(text))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue