Skip to content

Commit

Permalink
feat: Add search config to wrap jump_next and jump_prev
Browse files Browse the repository at this point in the history
Fixes folke#139
  • Loading branch information
ben-krieger committed Jan 15, 2024
1 parent 4a6737a commit d156c27
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Todo comes with the following defaults:
"--line-number",
"--column",
},
-- whether to wrap to the start (or end) of the file when searching
wrap = false,
-- regex that will be used to match keywords.
-- don't replace the (KEYWORDS) placeholder
pattern = [[\b(KEYWORDS):]], -- ripgrep regex
Expand Down
2 changes: 2 additions & 0 deletions lua/todo-comments/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ local defaults = {
"--line-number",
"--column",
},
-- whether to wrap to the start (or end) of the file when searching
wrap = false,
-- regex that will be used to match keywords.
-- don't replace the (KEYWORDS) placeholder
pattern = [[\b(KEYWORDS):]], -- ripgrep regex
Expand Down
36 changes: 35 additions & 1 deletion lua/todo-comments/jump.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,41 @@ local function jump(up, opts)
return
end
end
util.warn("No more todo comments to jump to")

if not config.options.search.wrap then
util.warn("No more todo comments to jump to")
return
end

if up then
from = vim.api.nvim_buf_line_count(buf)
to = pos[1]
else
from = 1
to = pos[1]
end

for l = from, to, up and -1 or 1 do
local line = vim.api.nvim_buf_get_lines(buf, l - 1, l, false)[1] or ""
local ok, start, _, kw = pcall(highlight.match, line)

if ok and start then
if config.options.highlight.comments_only and highlight.is_comment(buf, l - 1, start) == false then
kw = nil
end
end

if kw and #opts.keywords > 0 and not vim.tbl_contains(opts.keywords, kw) then
kw = nil
end

if kw then
vim.api.nvim_win_set_cursor(win, { l, start - 1 })
return
end
end

util.warn("No todo comments found")
end

function M.next(opts)
Expand Down

0 comments on commit d156c27

Please sign in to comment.