Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions lua/jumpy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ M.config = {
accept_all = "<leader>A",
reject_all = "<leader>X",
reprompt = "<leader>r",
quickfix = "<leader>q",
},
highlights = {
added = "JumpyAdded",
Expand Down Expand Up @@ -122,6 +123,9 @@ function M._setup_keymaps()
map("n", c.reprompt, function()
require("jumpy.prompt").reprompt()
end, opts)
map("n", c.quickfix, function()
require("jumpy.navigate").add_hunks_to_quickfix()
end, opts)
end

return M
38 changes: 38 additions & 0 deletions lua/jumpy/navigate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ function M.replace_hunk(bufnr, hunk_idx, new_lines)
render.update_hunk_lines(bufnr, hunk_idx, new_lines)
end

function M.add_hunks_to_quickfix()
local states = render.get_all_states()
local items = M._transform_hunks_to_quickfix(states)

if #items == 0 then
vim.notify("jumpy: no hunks", vim.log.levels.INFO)
return
end

vim.fn.setqflist(items, "r")
vim.cmd("copen")
end

function M._transform_hunks_to_quickfix(states)
local items = {}
for bufnr, state in pairs(states) do
for _, hunk in pairs(state.hunks) do
if hunk then
local text
if #hunk.added_lines > 0 then
text = "+ " .. hunk.added_lines[1]
else
text = "- " .. hunk.removed_lines[1]
end

table.insert(items, {
bufnr = bufnr,
lnum = hunk.old_start,
col = 1,
text = text,
})
end
end
end

return items
end

local offset_table = {}

function M._get_offset(bufnr, hunk_idx)
Expand Down
14 changes: 14 additions & 0 deletions lua/jumpy/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ function M.get_state(bufnr)
return buf_states[bufnr]
end

function M.get_all_states()
local states = {}
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(buf) then
local state = M.get_state(buf)
if state then
states[buf] = state
end
end
end

return states
end

function M.show(bufnr, hunks, original_lines, proposed_lines)
M.clear(bufnr)

Expand Down
Loading