Skip to content

Commit 974663f

Browse files
authored
fix(virtual indent): do not return virtual indentation for headlines (#716)
This ensures when the treesitter parser has errors, the manual indent sizing doesn't return virtual indentation for headlines.
1 parent 4e4d93a commit 974663f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lua/orgmode/ui/virtual_indent.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ function VirtualIndent:_get_indent_size(line, tree_has_errors)
5353
if tree_has_errors then
5454
local linenr = line
5555
while linenr > 0 do
56-
local _, level = vim.fn.getline(linenr):find('^%*+')
56+
-- We offset `linenr` by 1 because it's 0-indexed and `getline` is 1-indexed
57+
local _, level = vim.fn.getline(linenr + 1):find('^%*+')
5758
if level then
58-
return level + 1
59+
-- If the current line is a headline we should return no virtual indentation, otherwise
60+
-- return virtual indentation
61+
return (linenr == line and 0 or level + 1)
5962
end
6063
linenr = linenr - 1
6164
end

0 commit comments

Comments
 (0)