Highlight icons using highlight regions rather than matching rules
This commit is contained in:
@@ -161,6 +161,7 @@ end
|
|||||||
|
|
||||||
function M.get_lines(flattened_outline_items)
|
function M.get_lines(flattened_outline_items)
|
||||||
local lines = {}
|
local lines = {}
|
||||||
|
local hl_info = {}
|
||||||
for _, value in ipairs(flattened_outline_items) do
|
for _, value in ipairs(flattened_outline_items) do
|
||||||
local line = str_to_table(string.rep(" ", value.depth))
|
local line = str_to_table(string.rep(" ", value.depth))
|
||||||
|
|
||||||
@@ -194,10 +195,15 @@ function M.get_lines(flattened_outline_items)
|
|||||||
table.insert(final_prefix, " ")
|
table.insert(final_prefix, " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(lines, table_to_str(final_prefix) .. value.icon .. " " ..
|
local string_prefix = table_to_str(final_prefix)
|
||||||
|
local hl_start = #string_prefix + 1
|
||||||
|
local hl_end = #string_prefix + #value.icon
|
||||||
|
table.insert(lines, string_prefix .. value.icon .. " " ..
|
||||||
value.name)
|
value.name)
|
||||||
|
hl_type = config.options.symbols[symbols.kinds[value.kind]].hl
|
||||||
|
table.insert(hl_info, {hl_start, hl_end, hl_type})
|
||||||
end
|
end
|
||||||
return lines
|
return lines, hl_info
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_details(flattened_outline_items)
|
function M.get_details(flattened_outline_items)
|
||||||
|
|||||||
@@ -52,12 +52,6 @@ function M.setup_highlights()
|
|||||||
highlight_text("markers_horizontal", M.markers.horizontal,
|
highlight_text("markers_horizontal", M.markers.horizontal,
|
||||||
"SymbolsOutlineConnector")
|
"SymbolsOutlineConnector")
|
||||||
highlight_text("markers_bottom", M.markers.bottom, "SymbolsOutlineConnector")
|
highlight_text("markers_bottom", M.markers.bottom, "SymbolsOutlineConnector")
|
||||||
|
|
||||||
for _, value in ipairs(symbol_kinds) do
|
|
||||||
local symbol = symbols[value]
|
|
||||||
highlight_text(value, symbol.icon, symbol.hl)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ local function is_buffer_outline(bufnr)
|
|||||||
return string.match(name, "OUTLINE") ~= nil and ft == "Outline" and isValid
|
return string.match(name, "OUTLINE") ~= nil and ft == "Outline" and isValid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local hlns = vim.api.nvim_create_namespace("symbols-outline-icon-highlight")
|
||||||
|
|
||||||
function M.write_outline(bufnr, lines)
|
function M.write_outline(bufnr, lines)
|
||||||
if not is_buffer_outline(bufnr) then return end
|
if not is_buffer_outline(bufnr) then return end
|
||||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
|
||||||
@@ -19,6 +21,13 @@ function M.write_outline(bufnr, lines)
|
|||||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.add_highlights(bufnr, hl_info)
|
||||||
|
for line, line_hl in ipairs(hl_info) do
|
||||||
|
hl_start, hl_end, hl_type = unpack(line_hl)
|
||||||
|
vim.api.nvim_buf_add_highlight(bufnr, hlns, hl_type, line - 1, hl_start - 1, hl_end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local ns = vim.api.nvim_create_namespace("symbols-outline-virt-text")
|
local ns = vim.api.nvim_create_namespace("symbols-outline-virt-text")
|
||||||
|
|
||||||
function M.write_details(bufnr, lines)
|
function M.write_details(bufnr, lines)
|
||||||
@@ -41,11 +50,12 @@ end
|
|||||||
-- runs the whole writing routine where the text is cleared, new data is parsed
|
-- runs the whole writing routine where the text is cleared, new data is parsed
|
||||||
-- and then written
|
-- and then written
|
||||||
function M.parse_and_write(bufnr, flattened_outline_items)
|
function M.parse_and_write(bufnr, flattened_outline_items)
|
||||||
local lines = parser.get_lines(flattened_outline_items)
|
local lines, hl_info = parser.get_lines(flattened_outline_items)
|
||||||
M.write_outline(bufnr, lines)
|
M.write_outline(bufnr, lines)
|
||||||
|
|
||||||
clear_virt_text(bufnr)
|
clear_virt_text(bufnr)
|
||||||
local details = parser.get_details(flattened_outline_items)
|
local details = parser.get_details(flattened_outline_items)
|
||||||
|
M.add_highlights(bufnr, hl_info)
|
||||||
M.write_details(bufnr, details)
|
M.write_details(bufnr, details)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user