-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[RFC] Implement SearchCurrent for current match hl #11082
Conversation
Uses SearchCurrent to highlight the current match under cursor.
For reference: related Vim issue: vim/vim#2819 |
would it make sense to re-use
In |
@justinmk I reused IncSearch, I think that's better. I now redraw the screen in And here is how it looks like with Which I think looks better. I wonder if we should change the default IncSearch settings? (In order for the background to be green, I had to set the At this point, I think the basic prototype works exactly as expected. I have a few questions:
|
This simplification can be applied: diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index dc0e718d6..16c7804be 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -940,7 +940,6 @@ typedef struct {
buf_T *buf; // the buffer to search for a match
linenr_T lnum; // the line to search for a match
int attr; // attributes to be used for a match
- int attr_cur2; // attributes to be used for a current match
int attr_cur; // attributes currently active in win_line()
linenr_T first_lnum; // first lnum to search for multi-line pat
colnr_T startcol; // in win_line() points to char where HL starts
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index baa100333..766ad4657 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -3001,7 +3001,7 @@ win_line (
if (wp->w_cursor.lnum == lnum
&& wp->w_cursor.col >= (long)shl->startcol
&& wp->w_cursor.col < (long)shl->endcol) {
- shl->attr_cur = shl->attr_cur2;
+ shl->attr_cur = win_hl_attr(wp, HLF_I);
} else {
shl->attr_cur = shl->attr;
}
@@ -5613,7 +5613,6 @@ static void init_search_hl(win_T *wp)
search_hl.lnum = 0;
search_hl.first_lnum = 0;
search_hl.attr = win_hl_attr(wp, HLF_L);
- search_hl.attr_cur2 = win_hl_attr(wp, HLF_I);
// time limit is set at the toplevel, for all windows
} and things still work. @justinmk should I do that? I don't know what style is preferred. |
Sure. Note that Bram seems to prefer the SearchCurrent approach, so we should probably stick with that. It can be linked with IncSearch by default. |
Sure, I'll revert it. It should probably be called something like |
I updated the PR. Interesting is that before one did:
but now one has to do:
to get the same result. It looks like the IncSearch is doing some inverting. Anyway, the PR is now really simple. Just four very little changes. @justinmk do you think that this change looks good? If so, I'll start working on updating the tests to pass. |
Cannot merge without tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A change in cursor_spec.lua
should be needed:
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
index 03cd4bfd0..4c51547e2 100644
--- a/test/functional/ui/cursor_spec.lua
+++ b/test/functional/ui/cursor_spec.lua
@@ -212,10 +212,10 @@ describe('ui/cursor', function()
if m.blinkwait then m.blinkwait = 700 end
end
if m.hl_id then
- m.hl_id = 60
+ m.hl_id = 61
m.attr = {background = Screen.colors.DarkGray}
end
- if m.id_lm then m.id_lm = 61 end
+ if m.id_lm then m.id_lm = 62 end
end
-- Assert the new expectation.
BTW the SearchLastFoundMatch
name is really too long.
I think setting the highlight group somehow affects the matchit highlighting 2021-12-29.16-54-00.mp4Note: I changed the hl-group name to |
This would be very nice to have, but I need help from neovim developers to help me get this over the finish line. I need help with writing tests, as well as feedback if any changes are needed. |
Before any of that, we might want to bikeshed on the name; I agree that Then, I think the first thing would be to add the new highlight group here: Line 263 in c46f7ca
and here: Line 6164 in c46f7ca
(probably easiest to link it to IncSearch by default -- or Search , in the hope that this would require fewer changes).
Documentation goes here: Lines 5170 to 5172 in c46f7ca
For tests, a good starting point would be to adapt one of the tests here: https://github.com/neovim/neovim/blob/master/test/functional/ui/searchhl_spec.lua |
Do you mind if I take over this PR? I think I might be able to finish it if you don't have time |
@famiu I think you can take the silence for a "yes". |
Will work on it once I get the PC |
An initial attempt at this has been merged upstream (vim/vim#10133 (comment)), with some small issues. |
@famiu yes, please take over the PR. I don't have the time to learn enough about neovim to bring it over the finish line, it looks like tests have to be written etc. |
Superseded by #18081 |
Uses SearchCurrent to highlight the current match under cursor.
How to use: put this into your
init.vim
:Then the current match will be highlighted using
SearchCurrent
, while the rest will be highlighted usingSearch
. An example:Issues to resolve:
/int<CR>
(in the screenshot above) when the cursor is at some other place, and it will correctly highlight that new match. One has to figure how to redraw when "n" or "N" is pressed.SearchCurrent
Fixes #4600.