-
Notifications
You must be signed in to change notification settings - Fork 457
fix(nvim): keep grep match bg on preview target line #886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmtrKovalenko
merged 3 commits into
dmtrKovalenko:main
from
cmdrrobin:fix/preview-grep-match-bg
Sep 26, 2026
+102
−9
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| ---@diagnostic disable: undefined-field, need-check-nil | ||
| local location_utils = require('fff.location_utils') | ||
|
|
||
| --- Collect extmarks grouped by hl_group, asserting none use line_hl_group | ||
| --- @param buf number Buffer number | ||
| --- @param ns number Namespace to read extmarks from | ||
| --- @return table<string, table[]> marks Marks keyed by hl_group with row, col and details | ||
| local function marks_by_group(buf, ns) | ||
| local by_group = {} | ||
| for _, mark in ipairs(vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, { details = true })) do | ||
| local details = mark[4] | ||
| assert.is_nil(details.line_hl_group) | ||
| if details.hl_group then | ||
| by_group[details.hl_group] = by_group[details.hl_group] or {} | ||
| table.insert(by_group[details.hl_group], { row = mark[2], col = mark[3], details = details }) | ||
| end | ||
| end | ||
| return by_group | ||
| end | ||
|
|
||
| --- Assert a single full-width CursorLine mark on row, with lower priority than every match | ||
| --- @param marks table<string, table[]> Result of marks_by_group | ||
| --- @param match_group string Highlight group of the match marks | ||
| --- @param row number 0-based row expected to carry the CursorLine mark | ||
| local function assert_cursor_line_below(marks, match_group, row) | ||
| local cursor_line = marks.CursorLine[1] | ||
| assert.are.equal(1, #marks.CursorLine) | ||
| assert.are.equal(row, cursor_line.row) | ||
| assert.are.equal(0, cursor_line.col) | ||
| assert.are.equal(row + 1, cursor_line.details.end_row) | ||
| assert.is_true(cursor_line.details.hl_eol) | ||
| assert.are.equal('CursorLineNr', cursor_line.details.number_hl_group) | ||
|
|
||
| for _, match in ipairs(marks[match_group]) do | ||
| assert.is_true(match.details.priority > cursor_line.details.priority) | ||
| end | ||
| end | ||
|
|
||
| describe('location_utils highlight', function() | ||
| local buf, ns | ||
|
|
||
| before_each(function() | ||
| buf = vim.api.nvim_create_buf(false, true) | ||
| ns = vim.api.nvim_create_namespace('fff_location_utils_spec') | ||
| vim.api.nvim_buf_set_lines(buf, 0, -1, false, { 'hello world', 'abc hello x' }) | ||
| end) | ||
|
|
||
| after_each(function() vim.api.nvim_buf_delete(buf, { force = true }) end) | ||
|
|
||
| it('keeps fuzzy grep matches above the pinned cursor line', function() | ||
| location_utils.highlight_location(buf, { grep_query = 'hlo', line = 2, fuzzy_match_ranges = { { 4, 9 } } }, ns) | ||
| local marks = marks_by_group(buf, ns) | ||
| local grep_hl = require('fff.conf').get().hl.grep_match or 'IncSearch' | ||
|
|
||
| assert.are.equal(1, #marks[grep_hl]) | ||
| assert.are.equal(4, marks[grep_hl][1].col) | ||
| assert_cursor_line_below(marks, grep_hl, 1) | ||
| end) | ||
|
|
||
| it('keeps line:col highlight above the cursor line', function() | ||
| location_utils.highlight_location(buf, { line = 2, col = 5 }, ns) | ||
| local marks = marks_by_group(buf, ns) | ||
|
|
||
| assert.are.equal(4, marks.IncSearch[1].col) | ||
| assert_cursor_line_below(marks, 'IncSearch', 1) | ||
| end) | ||
|
|
||
| it('keeps single line range highlight above the cursor line', function() | ||
| location_utils.highlight_location(buf, { start = { line = 1, col = 1 }, ['end'] = { line = 1, col = 6 } }, ns) | ||
| local marks = marks_by_group(buf, ns) | ||
|
|
||
| assert.are.equal(0, marks.IncSearch[1].col) | ||
| assert.are.equal(5, marks.IncSearch[1].details.end_col) | ||
| assert_cursor_line_below(marks, 'IncSearch', 0) | ||
| end) | ||
| end) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.