-
Notifications
You must be signed in to change notification settings - Fork 1.3k
make FindNext and FindPrevious work with empty matches
#3572
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
Conversation
f5aebe4 to
b8e5022
Compare
|
This addresses Maybe that's ok, but maybe it means that we should take a simpler, "stateless" approach instead: if the match is empty and it is found at the current position (irrespective of the last match), advance the cursor and search again. Or maybe an even simpler approach (which Vim seems to take): always start searching not from the current cursor location but from the character next to it. But that might be debatable whether that is what users want. |
b8e5022 to
bf08642
Compare
I would say it's OK. You start from the current location and find something that matches. If you allow empty matches, then you cannot complain when you get one. |
bf08642 to
498b019
Compare
Ok, then irregardless of ...Answering myself: it seems there is actually a good reason to keep it stateless and check the current cursor position rather than the last match. Press Ctrl-f and search for |
I like that idea, but I see a problem: Suppose that you search for If you search for
I think this is because there is no distinction between an empty selection and no selection. I agree that this is not good currently. However, as explained above, it seems to me that one needs some kind of state. |
No, it doesn't move right again. I didn't mean that it moves right until it finds a non-empty match, I meant that it moves right just once, and searches again just once, not in a loop. Just so that it isn't stuck at the initial position. And of course I didn't mean actually moving the cursor, I meant just moving the start location of search.
I'm not sure what does this have to do with selection...
To be clear: this is not the current micro's behavior, this is a regression introduced by this PR. |
498b019 to
1085742
Compare
Don't worry, that's what I meant. I've forced-pushed a new version along the lines of your idea. |
This is a companion to #3566, as suggested by @dmaluka in this comment. If there is an empty match, then
FindNextwill move one rune to the right before starting the search andFindpreviouswill move one rune to the left.The new field
LastMatchofBufferkeeps track of the last match. I only initialize it after a search (that is, whenLastSearchis non-empty).When testing the PR, keep in mind that currently
^always matches the current position when searching downwards and$does the same when searching upwards. That should be addressed in a different PR.