Skip to content

fix(navigation): handle EOF deletion hunks - #550

Merged
esmuellert merged 2 commits into
mainfrom
fix/eof-deletion-hunk-navigation
Sep 6, 2026
Merged

fix(navigation): handle EOF deletion hunks#550
esmuellert merged 2 commits into
mainfrom
fix/eof-deletion-hunk-navigation

Conversation

@esmuellert

Copy link
Copy Markdown
Owner

Summary

  • clamp hunk cursor targets to the last valid line in the target buffer
  • allow ]c/[c to cross file boundaries when a deletion ends at EOF
  • clamp initial and pending cursor landings in side-by-side and inline views
  • centralize cursor clamping in lua/codediff/ui/view/cursor.lua
  • add a regression test for issue bug: next hunk gets stuck on deletion at end of file #479

Root cause

A deletion at the end of a file is represented by a valid half-open range such as modified [4, 4) when the modified buffer has only three lines. Navigation treated start_line = 4 as a cursor row. Neovim rejected that cursor position, the error was swallowed by pcall, and navigation returned success without advancing to the next file.

Fix

Cursor placement now converts diff boundary coordinates to valid buffer cursor coordinates before comparing or setting the cursor. This also fixes initial and cross-file landing in both layouts.

Closes #479

Testing

  • CODEDIFF_TEST_JOBS=2 make test-lua — 107 spec files passed
  • targeted cycle_hunks_across_files_spec.lua — 10 passed
  • stylua --check
  • git diff --check

@esmuellert
esmuellert merged commit 7a940d3 into main Sep 6, 2026
19 of 20 checks passed
@esmuellert
esmuellert deleted the fix/eof-deletion-hunk-navigation branch September 6, 2026 02:23
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.

bug: next hunk gets stuck on deletion at end of file

2 participants