Fix vim method/comment navigation with expanded diff hunks#47976
Merged
dinocosta merged 3 commits intozed-industries:mainfrom Feb 2, 2026
Merged
Fix vim method/comment navigation with expanded diff hunks#47976dinocosta merged 3 commits intozed-industries:mainfrom
dinocosta merged 3 commits intozed-industries:mainfrom
Conversation
The `method_motion` and `comment_motion` functions incorrectly treated raw buffer offsets as MultiBuffer offsets. When diff hunks are expanded, the MultiBuffer contains extra content (deleted lines from the git base), making these coordinate spaces different. The fix follows the same pattern already used by `section_motion`: - Use `map.buffer_snapshot().text_object_ranges()` which returns `Range<MultiBufferOffset>` with proper coordinate transformation - Keep offset as `MultiBufferOffset` throughout (don't extract `.0`) - Use `MultiBufferOffset(0)..offset` for the search range This ensures vim motions `]m`, `[m`, `]M`, `[M` (method navigation) and `]*`, `[*` (comment navigation) work correctly regardless of whether diff hunks are expanded or collapsed. Fixes zed-industries#46612 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add test coverage for `] /` and `[ /` motions when diff hunks are expanded. - Refactored both `method_motion` and `comment_motion` to avoid multiple calls to `DisplaySnapshot.buffer_snapshot`.
adb-sh
pushed a commit
to adb-sh/zed
that referenced
this pull request
Feb 5, 2026
…tries#47976) Previously, `]m`/`[m` (method) and `]/`/`[/` (comment) motions would navigate to incorrect positions when diff hunks were expanded. This was caused by extracting raw `usize` values from `MultiBufferOffset` and operating directly on the underlying buffer, which doesn't account for expanded diff hunk content. The fix properly uses `MultiBufferOffset` throughout and queries `text_object_ranges` on the `MultiBufferSnapshot` instead of the underlying buffer, ensuring correct coordinate mapping when diff content is displayed inline. Fixes zed-industries#46612 Release Notes: - Fixed vim method and comment navigation (`] m`, `[ m`, `] shift-m`, `[ shift-m`, `] /`, `[ /`) incorrectly positioning cursor when diff hunks are expanded --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: dino <dinojoaocosta@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
method_motionandcomment_motioncoordinate space mismatchsection_motionFixes #46612
Test plan
test_method_motion_with_expanded_diff_hunkstestcargo test -p vim --libpasses (454 tests)./script/clippy -p vimpassesRelease Notes:
] m,[ m,] shift-m,[ shift-m,] /,[ /) incorrectly positioning cursor when diff hunks are expanded🤖 Generated with Claude Code