Skip to content

Commit 8dd7b97

Browse files
committed
record match for all nodes
1 parent e9f2407 commit 8dd7b97

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lua/orgmode/org/indent.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ local function get_indent_for_match(matches, linenr, mode, bufnr)
6262
end
6363
return indent
6464
end
65-
if mode:match('^[iR]') and prev_line_match.type == 'listitem' and linenr - prev_linenr < 3 then
66-
-- In insert mode, we also count the non-listitem line *after* a listitem as
65+
-- node type is nil while inserting!
66+
local is_inserting = (not match.type) or mode:match('^[iR]')
67+
if is_inserting and prev_line_match.type == 'listitem' and linenr - prev_linenr < 3 then
68+
-- While inserting, we also count the non-listitem line *after* a listitem as
6769
-- part of the listitem. Keep in mind that double empty lines end a list as
6870
-- per Orgmode syntax.
6971
--
@@ -217,6 +219,9 @@ local get_matches = ts_utils.memoize_by_buf_tick(function(bufnr)
217219
end
218220
elseif type == 'paragraph' or type == 'drawer' or type == 'property_drawer' then
219221
opts.indent_type = 'other'
222+
for i = range.start.line, range['end'].line - 1 do
223+
matches[i + 1] = opts
224+
end
220225
end
221226
end
222227

@@ -254,9 +259,7 @@ local function indentexpr(linenr, bufnr)
254259
end
255260

256261
local indentexpr_cache = buf_indentexpr_cache[bufnr] or { prev_linenr = -1 }
257-
if indentexpr_cache.prev_linenr ~= linenr - 1 or not mode:lower():find('n') then
258-
indentexpr_cache.matches = get_matches(bufnr)
259-
end
262+
indentexpr_cache.matches = get_matches(bufnr)
260263

261264
-- Treesitter failed to parse the document (due to errors or missing tree)
262265
-- So we just fallback to autoindent

0 commit comments

Comments
 (0)