Skip to content

Commit

Permalink
feat: support dotrepeat for promo and todo_items (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
champignoom committed Oct 9, 2023
1 parent ab46a8a commit 2c43e6b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions lua/neorg/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,26 @@ function utils.read_files(files, callback)
end
end

-- following https://gist.github.com/kylechui/a5c1258cd2d86755f97b10fc921315c3
function utils.set_operatorfunc(f)
utils._neorg_operatorfunc = f
vim.go.operatorfunc = "v:lua.require'neorg'.utils._neorg_operatorfunc"
end

function utils.wrap_dotrepeat(event_handler)
return function(event)
utils._neorg_is_dotrepeat = false
utils.set_operatorfunc(function()
if utils._neorg_is_dotrepeat then
local pos = vim.fn.getpos('.')
event.buffer = pos[1]
event.cursor_position = {pos[2], pos[3]}
end
utils._neorg_is_dotrepeat = true
event_handler(event)
end)
vim.cmd("normal! g@l")
end
end

return utils
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/promo/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ module.public = {
end,
}
module.on_event = function(event)
module.on_event = neorg.utils.wrap_dotrepeat(function(event)
local row = event.cursor_position[1] - 1
if event.split_type[1] ~= "core.keybinds" then
Expand Down Expand Up @@ -349,7 +349,7 @@ module.on_event = function(event)
)
end
end
end
end)
module.events.subscribed = {
["core.keybinds"] = {
Expand Down
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/qol/todo_items/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ module.public = {
end,
}
module.on_event = function(event)
module.on_event = neorg.utils.wrap_dotrepeat(function(event)
local todo_str = "core.qol.todo_items.todo."
if event.split_type[1] == "core.keybinds" then
Expand Down Expand Up @@ -452,7 +452,7 @@ module.on_event = function(event)
)
end
end
end
end)
module.events.subscribed = {
["core.keybinds"] = {
Expand Down

0 comments on commit 2c43e6b

Please sign in to comment.