-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implemented ResetSearch
and allow action chaining of FindNext
and FindPrevious
#3333
Conversation
Looks good to me.
Just omitted, I believe. Like in the vast majority of actions. I wrote about it a long time ago in #2755 (comment) (and I still think it would be good to improve all those actions as well). |
How about now and here? Otherwise it will be a good idea/intention, but not more and we forget about it again. |
Absolutely. |
I would be happy to have a look. But due to time constraints, I hope it's okay if this can happen at the end of next week at the earliest. |
No worries, we're not in hurry. |
I didn't mean that it must be @masmu who has to implement it. :) |
FYI I'm gonna push a PR soon. |
See #3352. |
@@ -815,6 +815,7 @@ var BufKeyActions = map[string]BufKeyAction{ | |||
"ToggleRuler": (*BufPane).ToggleRuler, | |||
"ToggleHighlightSearch": (*BufPane).ToggleHighlightSearch, | |||
"UnhighlightSearch": (*BufPane).UnhighlightSearch, | |||
"ResetSearch": (*BufPane).ResetSearch, |
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.
Sorry for my late response.
As a last small change request: ResetSearch
should be added to keybindings.md#bindable-actions-and-bindable-keys.
If this is added it can be merged. 👍
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.
No worries. I was quite busy as well.
Good catch!
I noticed that there are other actions missing in the keybindings.md
. Such as ToggleHighlightSearch
, UnhighlightSearch
and probably others. Isn't there are better way to keep that part of keybindings.md
in sync with the BufKeyActions map?
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.
Isn't there are better way to keep that part of
keybindings.md
in sync with the BufKeyActions map?
Currently I can only imagine to generate some parts of the docs via e.g. make doc
.
Added ResetSearch to the list of bindable actions in keybindings.md
30cb84b
to
bbf6ec2
Compare
This is a small feature to reset previously initiated searches and to use
FindNext
andFindPrevious
in chained actions.Personally I never could get used to use different shortcuts for initiating and continuing a search. (First
Ctrl-f
, thenCtrl-n
orCtrl-p
)Assuming that the option
hlsearch
is set tofalse
, my preferred workflow is:Initiation of a search:
Ctrl-f
(to open the search query box in the command bar)Enter
to start the searchExpectation: The first occurrence of the search term is being highlighted
Continuation of a previously initiated search:
Enter
to continue the searchExpectation: The next occurrence of the search term is being highlighted.
You can repeat this step as often as you like. Each
Enter
highlights the next occurrence.Exit the search operation when you found what you are looking for
Esc
to exitExpectation: The search term found is still highlighted and you can continue with normal text editing.
To achieve this chaining actions seems like the way to go. Like:
But this didn't work, since
BufPane.FindNext()
andBufPane.FindPrevious()
always returntrue
, which prevents all subsequent actions from being executed.I'm not sure if this is intentional for some reason. It seems more likely that this case was omitted or forgotten because it generally excludes the possibility of chaining actions.
Buffer.FindNext()
handles the case of a search term being empty. But it would also reset the selection when adding areturn false
there.So adding a guard clause at the top of the function may be the best solution and should not break any potential user bindings out there.
The missing piece left was to add
ResetSearch()
which allows to exit a previously initiated search. Like:Just as a bonus:
The following snippet adds a visual representation for being in search mode to the status line, which is IMHO quite nice.