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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ https://github.com/user-attachments/assets/64c41f01-dffe-4318-bce4-16eec8de356e
hide_merge_artifacts = false, -- Hide merge tool temp files (*.orig, *.BACKUP.*, *.BASE.*, *.LOCAL.*, *.REMOTE.*)
original_position = "left", -- Position of original (old) content: "left" or "right"
conflict_ours_position = "right", -- Position of ours (:2) in conflict view: "left" or "right"
cycle_next_hunk = true, -- Wrap around when navigating hunks (]c/[c): false to stop at first/last
},

-- Explorer panel configuration
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.16.5
2.17.0
1 change: 1 addition & 0 deletions lua/codediff/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ M.defaults = {
hide_merge_artifacts = false, -- Hide merge tool temp files (*.orig, *.BACKUP.*, *.BASE.*, *.LOCAL.*, *.REMOTE.*)
original_position = "left", -- Position of original (old) content: "left" or "right"
conflict_ours_position = "right", -- Position of ours (:2) in conflict view: "left" or "right" (independent of original_position)
cycle_next_hunk = true, -- Wrap around when navigating hunks (]c/[c): true = cycle, false = stop at first/last
},

-- Explorer panel configuration
Expand Down
28 changes: 18 additions & 10 deletions lua/codediff/ui/view/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ function M.setup_all_keymaps(tabpage, original_bufnr, modified_bufnr, is_explore
end
end

-- Wrap around to first hunk
local first_hunk = diff_result.changes[1]
local target_line = is_original and first_hunk.original.start_line or first_hunk.modified.start_line
pcall(vim.api.nvim_win_set_cursor, 0, { target_line, 0 })
vim.api.nvim_echo({ { string.format("Hunk 1 of %d", #diff_result.changes), "None" } }, false, {})
-- Wrap around to first hunk (if cycling enabled)
if config.options.diff.cycle_next_hunk then
local first_hunk = diff_result.changes[1]
local target_line = is_original and first_hunk.original.start_line or first_hunk.modified.start_line
pcall(vim.api.nvim_win_set_cursor, 0, { target_line, 0 })
vim.api.nvim_echo({ { string.format("Hunk 1 of %d", #diff_result.changes), "None" } }, false, {})
else
vim.api.nvim_echo({ { string.format("Last hunk (%d of %d)", #diff_result.changes, #diff_result.changes), "WarningMsg" } }, false, {})
end
end

-- Helper: Navigate to previous hunk
Expand Down Expand Up @@ -110,11 +114,15 @@ function M.setup_all_keymaps(tabpage, original_bufnr, modified_bufnr, is_explore
end
end

-- Wrap around to last hunk
local last_hunk = diff_result.changes[#diff_result.changes]
local target_line = is_original and last_hunk.original.start_line or last_hunk.modified.start_line
pcall(vim.api.nvim_win_set_cursor, 0, { target_line, 0 })
vim.api.nvim_echo({ { string.format("Hunk %d of %d", #diff_result.changes, #diff_result.changes), "None" } }, false, {})
-- Wrap around to last hunk (if cycling enabled)
if config.options.diff.cycle_next_hunk then
local last_hunk = diff_result.changes[#diff_result.changes]
local target_line = is_original and last_hunk.original.start_line or last_hunk.modified.start_line
pcall(vim.api.nvim_win_set_cursor, 0, { target_line, 0 })
vim.api.nvim_echo({ { string.format("Hunk %d of %d", #diff_result.changes, #diff_result.changes), "None" } }, false, {})
else
vim.api.nvim_echo({ { string.format("First hunk (1 of %d)", #diff_result.changes), "WarningMsg" } }, false, {})
end
end

-- Helper: Navigate to next file (works in both explorer and history mode)
Expand Down