fix(markdown): Don't include next heading in previous heading's range

Somehow marksman also does this?

As for treesitter (norg) it may be because treesitter includes the
newline and the next line indent until the next heading, so the line of
the next heading is included in the range of the previous heading. We
manually -1 on the range end line to fix it.
This commit is contained in:
hedy
2023-11-24 14:59:45 +08:00
parent 2d936bce2d
commit ebf90dc9ee
3 changed files with 15 additions and 9 deletions

View File

@@ -80,8 +80,11 @@ function M.handle_markdown()
for i = depth, max_level do
if level_symbols[i] ~= nil then
level_symbols[i].selectionRange['end'].line = line - 1
level_symbols[i].range['end'].line = line - 1
-- -1 for 0-index, -1 to not include current line
-- TODO: This fix can be removed when we let highlight_hovered_item
-- account for current column position in addition to the line
level_symbols[i].selectionRange['end'].line = line - 2
level_symbols[i].range['end'].line = line - 2
level_symbols[i] = nil
end
end
@@ -106,13 +109,6 @@ function M.handle_markdown()
::nextline::
end
for i = 2, max_level do
if level_symbols[i] ~= nil then
level_symbols[i].selectionRange['end'].line = #lines
level_symbols[i].range['end'].line = #lines
end
end
return level_symbols[1].children
end

View File

@@ -102,6 +102,11 @@ function M.request_symbols(callback, opts)
local current = {
kind = 15,
name = title,
-- Treesitter includes the last newline in the end range which spans
-- until the next heading, so we -1
-- TODO: This fix can be removed when we let highlight_hovered_item
-- account for current column position in addition to the line.
-- FIXME: By the way the end character should be the EOL
selectionRange = {
start = { character = col1, line = row1 },
['end'] = { character = col2, line = row2 - 1 },