Skip to content

Commit

Permalink
feat(todo_items): configurable parent update behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Sep 2, 2024
1 parent 6808e5e commit 2e720a2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lua/neorg/modules/core/qol/todo_items/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ module.config.public = {
-- ```
create_todo_parents = false,

-- Automatically update the parent todo state when a child node is updated.
--
-- eg:
-- ```norg
-- - ( ) parent
-- -- ( ) child
-- ```
-- Marking `-- ( ) child` as done (with a keybind) will result in:
-- ```norg
-- - (-) parent
-- -- (x) child
-- ```
update_todo_parents = true,

-- When `true`, will automatically create a TODO extension for an item
-- if it does not exist and an operation is performed on that item.
--
Expand Down Expand Up @@ -325,6 +339,7 @@ module.private = {

local first_status_extension = module.private.find_first_status_extension(node:named_child(1)) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>

local parent_line
if not first_status_extension then
if not module.config.public.create_todo_items then
return
Expand All @@ -333,9 +348,10 @@ module.private = {
local row, _, _, column = node:named_child(0):range() ---@diagnostic disable-line -- TODO: type error workaround <pysan3>

vim.api.nvim_buf_set_text(buf, row, column, row, column, { "(" .. char .. ") " })
module.private.update_parent(buf, row, 0)
parent_line = row
else
local range = module.required["core.integrations.treesitter"].get_node_range(first_status_extension)
parent_line = range.row_start

vim.api.nvim_buf_set_text(
buf,
Expand All @@ -345,7 +361,10 @@ module.private = {
range.column_end,
{ char }
)
module.private.update_parent(buf, range.row_start, 0)
end

if module.config.public.update_todo_parents then
module.private.update_parent(buf, parent_line, 0)
end

for child in node:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
Expand Down

0 comments on commit 2e720a2

Please sign in to comment.