feat(parser): Fix guide highlight for multi-width characters
This commit is contained in:
@@ -169,6 +169,7 @@ local function handler(response)
|
|||||||
wipe_state()
|
wipe_state()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
setup_keymaps(M.view.bufnr)
|
setup_keymaps(M.view.bufnr)
|
||||||
|
|
||||||
local items = parser.parse(response)
|
local items = parser.parse(response)
|
||||||
@@ -178,6 +179,7 @@ local function handler(response)
|
|||||||
|
|
||||||
writer.parse_and_write(M.view.bufnr, M.state.flattened_outline_items)
|
writer.parse_and_write(M.view.bufnr, M.state.flattened_outline_items)
|
||||||
|
|
||||||
|
|
||||||
M._highlight_current_item(M.state.code_win)
|
M._highlight_current_item(M.state.code_win)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -183,48 +183,73 @@ function M.get_lines(flattened_outline_items)
|
|||||||
|
|
||||||
for node_line, node in ipairs(flattened_outline_items) do
|
for node_line, node in ipairs(flattened_outline_items) do
|
||||||
local line = str_to_table(string.rep(' ', node.depth))
|
local line = str_to_table(string.rep(' ', node.depth))
|
||||||
|
local running_length = 1
|
||||||
|
|
||||||
|
local function add_guide_hl(from, to)
|
||||||
|
table.insert(hl_info, {
|
||||||
|
node_line,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
'SymbolsOutlineConnector',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
if config.options.show_guides then
|
if config.options.show_guides then
|
||||||
-- makes the guides
|
-- makes the guides
|
||||||
|
|
||||||
for index, _ in ipairs(line) do
|
for index, _ in ipairs(line) do
|
||||||
local guide_hl_type = 'SymbolsOutlineConnector'
|
|
||||||
-- all items start with a space (or two)
|
-- all items start with a space (or two)
|
||||||
if index == 1 then
|
if index == 1 then
|
||||||
line[index] = ' '
|
line[index] = ' '
|
||||||
guide_hl_type = 'Normal'
|
|
||||||
-- i f index is last, add a bottom marker if current item is last,
|
-- i f index is last, add a bottom marker if current item is last,
|
||||||
-- else add a middle marker
|
-- else add a middle marker
|
||||||
elseif index == #line then
|
elseif index == #line then
|
||||||
if node.isLast then
|
if node.isLast then
|
||||||
line[index] = ui.markers.bottom
|
line[index] = ui.markers.bottom
|
||||||
|
add_guide_hl(
|
||||||
|
running_length,
|
||||||
|
running_length + vim.fn.strlen(ui.markers.bottom) - 1
|
||||||
|
)
|
||||||
else
|
else
|
||||||
line[index] = ui.markers.middle
|
line[index] = ui.markers.middle
|
||||||
|
add_guide_hl(
|
||||||
|
running_length,
|
||||||
|
running_length + vim.fn.strlen(ui.markers.middle) - 1
|
||||||
|
)
|
||||||
end
|
end
|
||||||
-- else if the parent was not the last in its group, add a
|
-- else if the parent was not the last in its group, add a
|
||||||
-- vertical marker because there are items under us and we need
|
-- vertical marker because there are items under us and we need
|
||||||
-- to point to those
|
-- to point to those
|
||||||
elseif not node.hierarchy[index] then
|
elseif not node.hierarchy[index] then
|
||||||
line[index] = ui.markers.vertical
|
line[index] = ui.markers.vertical
|
||||||
|
add_guide_hl(
|
||||||
|
running_length,
|
||||||
|
running_length + vim.fn.strlen(ui.markers.vertical) - 1
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
line[index] = line[index] .. ' '
|
line[index] = line[index] .. ' '
|
||||||
|
|
||||||
local guide_hl_start = index * 2
|
running_length = running_length + vim.fn.strlen(line[index])
|
||||||
local guide_hl_end = index * 2 + #line[index]
|
|
||||||
|
|
||||||
table.insert(
|
|
||||||
hl_info,
|
|
||||||
{ node_line, guide_hl_start, guide_hl_end, guide_hl_type }
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local final_prefix = line
|
local final_prefix = line
|
||||||
|
|
||||||
local string_prefix = table_to_str(final_prefix)
|
local string_prefix = table_to_str(final_prefix)
|
||||||
|
|
||||||
|
-- local guide_hl_start = 0
|
||||||
|
-- local guide_hl_end = #string_prefix
|
||||||
|
|
||||||
|
-- table.insert(
|
||||||
|
-- hl_info,
|
||||||
|
-- { node_line, guide_hl_start, guide_hl_end, 'SymbolsOutlineConnector' }
|
||||||
|
-- )
|
||||||
|
|
||||||
|
table.insert(lines, string_prefix .. node.icon .. ' ' .. node.name)
|
||||||
|
|
||||||
local hl_start = #string_prefix
|
local hl_start = #string_prefix
|
||||||
local hl_end = #string_prefix + #node.icon
|
local hl_end = #string_prefix + #node.icon
|
||||||
table.insert(lines, string_prefix .. node.icon .. ' ' .. node.name)
|
|
||||||
local hl_type = config.options.symbols[symbols.kinds[node.kind]].hl
|
local hl_type = config.options.symbols[symbols.kinds[node.kind]].hl
|
||||||
table.insert(hl_info, { node_line, hl_start, hl_end, hl_type })
|
table.insert(hl_info, { node_line, hl_start, hl_end, hl_type })
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user