Skip to content

feat: add public hunk navigation API - #3

Open
leolaurindo wants to merge 1 commit into
cvlmtg:mainfrom
leolaurindo:feat/hunk-navigation
Open

feat: add public hunk navigation API#3
leolaurindo wants to merge 1 commit into
cvlmtg:mainfrom
leolaurindo:feat/hunk-navigation

Conversation

@leolaurindo

Copy link
Copy Markdown

Expose change-hunk navigation as a public API instead of forcing users to
read the internal prev_hunks state. Adds:

  • inline-diff.next_hunk() / inline-diff.prev_hunk() Lua functions, jumping
    the cursor to the next/previous hunk (wrapping at either end) and
    returning the target line or nil when there are no hunks
  • :InlineDiffNext / :InlineDiffPrev user commands wrapping the API

Includes 7 tests covering next/prev, wrap-around, the no-hunks case, and
clamping of deletions at line 0.

The plugin already computes and stores the current buffer's hnks interally in prev_hunks. So consumers that want hunk navigation already can do that, but need to access internal state directly (and make a wrap in accessible through init.lua). Navigation depends on

require("inline-diff.state").get(bufnr).prev_hunks

What I did was to create a set of public functions that provide stable integration without exposing state representation.

next_hunk():

  • Jumps to the next hunk after the cursor
  • Wraps to the first hunk after the last one
  • Returns the target 1-based line
  • Returns nil when the buffer is disabled or has no hunks

prev_hunk() behaves symmetrically and wraps to the final hunk.

The commands are thin wrappers around the public API.

Testing

Added tests covering:

  • Next-hunk navigation
  • Previous-hunk navigation
  • Wrap-around in both directions
  • No-hunk behavior
  • Deletions anchored before line 1

Full test suite passes:
Success: 23
Failed: 0
Errors: 0

The combined demo branch is available at:
https://github.com/leolaurindo/inline-diff.nvim/tree/dev/al

Expose change-hunk navigation as a public API instead of forcing users to
read the internal prev_hunks state. Adds:

- inline-diff.next_hunk() / inline-diff.prev_hunk() Lua functions, jumping
  the cursor to the next/previous hunk (wrapping at either end) and
  returning the target line or nil when there are no hunks
- :InlineDiffNext / :InlineDiffPrev user commands wrapping the API

Includes 7 tests covering next/prev, wrap-around, the no-hunks case, and
clamping of deletions at line 0.
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.

1 participant