From fd6b744ac0b341393ed8be79e705e0fc18968255 Mon Sep 17 00:00:00 2001 From: Yanuo Ma Date: Thu, 5 Feb 2026 00:03:50 -0500 Subject: [PATCH 1/2] feat: add cycle_next_hunk option to disable hunk navigation wrap-around Adds diff.cycle_next_hunk config option (default: true) that controls whether ]c/[c navigation wraps around when reaching the first/last hunk. When set to false, navigation stops at boundaries and shows a warning message indicating the user is at the first or last hunk. Closes #219 --- README.md | 1 + lua/codediff/config.lua | 1 + lua/codediff/ui/view/keymaps.lua | 28 ++++++++++++++++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8f7f5708..3580749f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/codediff/config.lua b/lua/codediff/config.lua index a87ce23e..c359cdb9 100644 --- a/lua/codediff/config.lua +++ b/lua/codediff/config.lua @@ -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 = false, -- Wrap around when navigating hunks (]c/[c): true = cycle, false = stop at first/last }, -- Explorer panel configuration diff --git a/lua/codediff/ui/view/keymaps.lua b/lua/codediff/ui/view/keymaps.lua index 34795bb2..60279520 100644 --- a/lua/codediff/ui/view/keymaps.lua +++ b/lua/codediff/ui/view/keymaps.lua @@ -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 @@ -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) From 184827f2305025a056062a7291f9e03be2eb6cb3 Mon Sep 17 00:00:00 2001 From: Yanuo Ma Date: Thu, 5 Feb 2026 00:04:16 -0500 Subject: [PATCH 2/2] chore: bump version to 2.17.0 --- VERSION | 2 +- lua/codediff/config.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index ffa5fee5..d76bd2ba 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.16.5 +2.17.0 diff --git a/lua/codediff/config.lua b/lua/codediff/config.lua index c359cdb9..bff256b1 100644 --- a/lua/codediff/config.lua +++ b/lua/codediff/config.lua @@ -34,7 +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 = false, -- Wrap around when navigating hunks (]c/[c): true = cycle, false = stop at first/last + cycle_next_hunk = true, -- Wrap around when navigating hunks (]c/[c): true = cycle, false = stop at first/last }, -- Explorer panel configuration