Skip to content

Commit 38aad1b

Browse files
committed
Append to list with no children
Previous implementation would error if the list you wanted to append to didn't have any children. This makes sure that it will work.
1 parent 2b9afa5 commit 38aad1b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lua/neorg/modules/external/capture/module.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,20 @@ module.private = {
126126
if data.headline then
127127
local ts = module.required['core.integrations.treesitter']
128128
local query = "( (heading1 title: (paragraph_segment) @title_text) (#eq? @title_text " .. data.headline .. ") ) @next-segment"
129+
130+
local end_line = function(node, child_count)
131+
if child_count > 0 then
132+
local child = node:child(child_count - 1)
133+
return child:end_()
134+
else
135+
return node:end_()
136+
end
137+
end
138+
129139
local cb = function(_, _, node, _)
130140
local child_count = node:child_count()
131-
local child = node:child(child_count - 1)
132-
local end_line = child:end_()
133-
vim.api.nvim_buf_set_lines(0, end_line, end_line, false, lines)
141+
local end_linenr = end_line(node, child_count)
142+
vim.api.nvim_buf_set_lines(0, end_linenr, end_linenr, false, lines)
134143
vim.cmd.write({ args = { path }, bang = true })
135144
return true
136145
end

0 commit comments

Comments
 (0)