Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todo_item parent update behaviors #1568

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 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,8 +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 .. ") " })
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 @@ -346,6 +363,10 @@ module.private = {
)
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>
if type == child:type():match("^(.+)%d+$") then
module.private.make_all(buf, child, todo_item_type, char)
Expand Down
Loading