From 6808e5ed9dbdf4da7bf90b7f993ab4922b0645d0 Mon Sep 17 00:00:00 2001 From: Ben Lubas Date: Mon, 2 Sep 2024 12:14:32 -0400 Subject: [PATCH 1/2] fix(todo_items): update parent node when child state is changed --- lua/neorg/modules/core/qol/todo_items/module.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/neorg/modules/core/qol/todo_items/module.lua b/lua/neorg/modules/core/qol/todo_items/module.lua index 7bcf97e35..da7656b71 100644 --- a/lua/neorg/modules/core/qol/todo_items/module.lua +++ b/lua/neorg/modules/core/qol/todo_items/module.lua @@ -333,6 +333,7 @@ module.private = { local row, _, _, column = node:named_child(0):range() ---@diagnostic disable-line -- TODO: type error workaround vim.api.nvim_buf_set_text(buf, row, column, row, column, { "(" .. char .. ") " }) + module.private.update_parent(buf, row, 0) else local range = module.required["core.integrations.treesitter"].get_node_range(first_status_extension) @@ -344,6 +345,7 @@ module.private = { range.column_end, { char } ) + module.private.update_parent(buf, range.row_start, 0) end for child in node:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround From 2e720a2b4ef2e5ecd09e0945673e53e335a1745b Mon Sep 17 00:00:00 2001 From: Ben Lubas Date: Mon, 2 Sep 2024 12:25:34 -0400 Subject: [PATCH 2/2] feat(todo_items): configurable parent update behavior --- .../modules/core/qol/todo_items/module.lua | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/qol/todo_items/module.lua b/lua/neorg/modules/core/qol/todo_items/module.lua index da7656b71..7b51f4e54 100644 --- a/lua/neorg/modules/core/qol/todo_items/module.lua +++ b/lua/neorg/modules/core/qol/todo_items/module.lua @@ -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. -- @@ -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 + local parent_line if not first_status_extension then if not module.config.public.create_todo_items then return @@ -333,9 +348,10 @@ module.private = { local row, _, _, column = node:named_child(0):range() ---@diagnostic disable-line -- TODO: type error workaround 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, @@ -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