Skip to content

feat: expose navigation API (next_hunk, prev_hunk, next_file, prev_file)#228

Merged
esmuellert merged 2 commits intomainfrom
dev/main
Feb 5, 2026
Merged

feat: expose navigation API (next_hunk, prev_hunk, next_file, prev_file)#228
esmuellert merged 2 commits intomainfrom
dev/main

Conversation

@esmuellert
Copy link
Owner

Summary

Exposes navigation functions as public API, allowing users to customize navigation behavior (e.g., centering view after jumps).

Closes #217

Changes

  • New file: lua/codediff/ui/view/navigation.lua - standalone navigation module
  • Updated: lua/codediff/init.lua - exports next_hunk(), prev_hunk(), next_file(), prev_file()
  • Refactored: lua/codediff/ui/view/keymaps.lua - uses navigation module instead of inline functions
  • New test: tests/api_spec.lua - verifies API exports

Usage

local codediff = require('codediff')

-- Example: center view after each jump (from issue #217)
vim.keymap.set('n', ']c', function()
  codediff.next_hunk()
  vim.cmd('zz')
end, { desc = 'Next hunk (centered)' })

vim.keymap.set('n', '[c', function()
  codediff.prev_hunk()
  vim.cmd('zz')
end, { desc = 'Prev hunk (centered)' })

API

Function Description
next_hunk() Navigate to next diff hunk. Returns true if succeeded.
prev_hunk() Navigate to previous diff hunk. Returns true if succeeded.
next_file() Navigate to next file (or next commit in single-file history mode). Returns true if succeeded.
prev_file() Navigate to previous file. Returns true if succeeded.

Closes #217

- Add navigation.lua module with standalone navigation functions
- Export next_hunk(), prev_hunk(), next_file(), prev_file() on main API
- Refactor keymaps.lua to use navigation module
- Add api_spec.lua tests for exported functions

Users can now customize navigation behavior:
  local codediff = require('codediff')
  vim.keymap.set('n', ']c', function()
    codediff.next_hunk()
    vim.cmd('zz')  -- center after jump
  end)
@esmuellert esmuellert enabled auto-merge February 5, 2026 05:34
@esmuellert esmuellert merged commit 648610c into main Feb 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: export actions such as next_hunk/prev_hunk?

1 participant