Skip to content

Commit

Permalink
feat: keep checkboxes with core.itero (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jan 2, 2023
1 parent 7077717 commit 00532bd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lua/neorg/modules/core/itero/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.config.public = {
"heading%d",
"quote%d",
},

-- Which items to retain extensions for
retain_extensions = {
["unordered_list%d"] = true,
["ordered_list%d"] = true,
},
}

module.config.private = {
Expand Down Expand Up @@ -67,10 +73,26 @@ module.on_event = function(event)
return
end

local should_append_extension = neorg.lib.filter(
module.config.public.retain_extensions,
function(match, should_append)
return current:type():match(match) and should_append or nil
end
) and current:named_child(1) and current:named_child(1):type() == "detached_modifier_extension"

local text_to_repeat = ts.get_node_text(current:named_child(0), event.buffer)

vim.api.nvim_buf_set_lines(event.buffer, cursor_pos + 1, cursor_pos + 1, true, { text_to_repeat })
vim.api.nvim_win_set_cursor(event.window, { cursor_pos + 2, text_to_repeat:len() })
vim.api.nvim_buf_set_lines(
event.buffer,
cursor_pos + 1,
cursor_pos + 1,
true,
{ text_to_repeat .. (should_append_extension and "( ) " or "") }
)
vim.api.nvim_win_set_cursor(
event.window,
{ cursor_pos + 2, text_to_repeat:len() + (should_append_extension and ("( ) "):len() or 0) }
)
end
end

Expand Down

0 comments on commit 00532bd

Please sign in to comment.