refactor: make_outline function and left padding of lineno

This commit is contained in:
hedy
2023-11-13 15:41:54 +08:00
parent 60e8cadb46
commit 7713536d28

View File

@@ -159,7 +159,9 @@ function M.make_outline(bufnr, items)
table.insert(flattened, node) table.insert(flattened, node)
node.line_in_outline = #flattened node.line_in_outline = #flattened
table.insert(details, node.detail or '') table.insert(details, node.detail or '')
table.insert(linenos, tostring(node.range_start+1)) local lineno = tostring(node.range_start+1)
local leftpad = string.rep(' ', lineno_max_width-#lineno)
table.insert(linenos, leftpad..lineno)
-- Make the guides for the line prefix -- Make the guides for the line prefix
local pref = t_utils.str_to_table(string.rep(' ', node.depth)) local pref = t_utils.str_to_table(string.rep(' ', node.depth))
@@ -248,12 +250,12 @@ function M.make_outline(bufnr, items)
-- Line numbers are left padded, right aligned, positioned at the leftmost -- Line numbers are left padded, right aligned, positioned at the leftmost
-- column -- column
for index, value in ipairs(linenos) do for index, value in ipairs(linenos) do
local leftpad = string.rep(' ', lineno_max_width-#value)
vim.api.nvim_buf_set_extmark(bufnr, ns, index - 1, -1, { vim.api.nvim_buf_set_extmark(bufnr, ns, index - 1, -1, {
virt_text = { {leftpad..value, 'OutlineLineno' } }, virt_text = { { value, 'OutlineLineno' } },
virt_text_pos = 'overlay', virt_text_pos = 'overlay',
virt_text_win_col = 0, virt_text_win_col = 0,
hl_mode = 'combine', virt_text_hide = true,
hl_mode = 'replace',
}) })
end end
end end