Closed jeremyckahn closed 6 years ago
Thank you for such a clean issue description! In short, currently there is no such a way that makes ctrlsf automatically focus result window when searching is done. It used to be so in my initial implementation of async search, but I found it may surprise user when they are typing a series of keys, then interrupted by this "auto focus".
I can't find out a proper approach. Any idea?
Admittedly I don’t know the first thing about Vim plugin development, so I’m not aware of what constraints and practical considerations might make this feature difficult to implement. I’m envisioning the CtrlSF pane window being focused as soon as it opens, not once the search is complete. Would that make this feature easier to implement?
If this requires a lot of work on your end to figure out a solution for, I’d be happy to help figure it out too once I have a bit of time, so just let me know what works for you! I’ve never used VimL but I’m willing to learn a bit. 🙂
Thanks for your kindly help! The implementation is quite straightforward, but I have assumed that users are using async search as they can do their work while search is processing, so I'm not sure if this 'auto focus' is what they want.
Anyway, I have implemented a prototype at branch feature/auto-focus-result-pane
. There are two options: g:ctrlsf_focus_at_start
and g:ctrlsf_focus_at_done
, which means focus at searching start and end. Please take it a try, your feedback is welcome!
I have implemented another approach that ctrlsf can auto focus result pane for those short lived search. Option g:ctrlsf_short_search_duration
defines how long a search is considered short lived. Current value is 1000
, which means 1000 milliseconds. Please tell me which one suits your need best. 🙂
@dyng Thank you so much for taking the time to implement this feature! g:ctrlsf_focus_at_start
gives me exactly the functionality I'm looking for, so my needs are met with that. I see what you're saying about the behavior of g:ctrlsf_focus_at_done
being a little odd; it doesn't feel terribly helpful as a user to have the cursor change windows at a seemingly randomly time.
I'm not totally sure how to use g:ctrlsf_short_search_duration
. Is the idea there to focus the results window after a specified timeout?
Either way, I'm completely satisfied with g:ctrlsf_focus_at_start
, so to me this is good to merge. I will leave it up to you to decide what to do with g:ctrlsf_focus_at_done
and g:ctrlsf_short_search_duration
. Thanks again for doing this work!
I was looking for this exact same functionality today. Thanks @jeremyckahn for the OP and thanks @dyng for implementing it. I've checked out feature/auto-focus-result-pane
and it works like a charm.
I'm in the same boat as @jeremyckahn-- g:ctrlsf_focus_at_start
gives me exactly what I want.
I think setting g:ctrlsf_focus_at_start
to 1
is a sensible default. That said, I'd understand if you don't want to break backwards compatibility, and I don't think it should block this feature from landing.
Edit: IIRC, focusing the result pane from the start used to be the default (before ctrlsf supported async). So setting ctrlsf_focus_at_start = 1
by default might actually restore backwards compatibility.
I think there are two timings to focus the result window: at start and at done. For sync search mode, it’s at done in MY MIND, so focus at start is not restoring backward compatibility, although there is no actual difference between at start and at done for sync search mode, because users can do nothing during the interval between start and done. But it is not true for async search mode, and that is why I hesitated on which should be default.
But I have my plan now. For async search mode, not focus by default and let user decide which timing to focus. For sync search mode, nothing changes.
@dyng Sounds like a good plan!
@jeremyckahn @sloria merged, please take it a try. Note that the new option name is g:ctrlsf_auto_focus
, and you can set it like
let g:ctrlsf_auto_focus = {
\ 'at': 'start',
\ }
@dyng Thanks! Just gave it a try and it seems to be working with the above config. The first result doesn't get auto-focused, however (the cursor starts at the top of the screen). Is that expected?
@sloria Yes, the cursor can't be placed at first result because window get focused at the starting of search, when the results have not been fed by backend yet.
OK. FWIW, I like the previous behavior of focusing the first result, but it's not a big deal; I'm happy with it as is.
@dyng Thank you for polishing and merging this feature! I really appreciate the work. I agree with @sloria that it's preferable to have the first result focused, but that's a very minor issue and I am just happy to have the result pane focused after running a search.
Thanks again for doing this!
@jeremyckahn @sloria Thanks for your suggestions too!
@jeremyckahn @sloria Finally I found out a way to focus the first result now!
Just tried it it out; works great!
Works perfectly for me too. Thanks for taking the time to do this, @dyng!
For some reason, the first result no longer gets autofocused for me. I am up to date with the latest version. @dyng Would you like me to open a separate issue?
@sloria Ok, please open a new issue.
It seems to be happening probabilistically--I can't reliably reproduce it. I'll post an issue if/when I get more time to dig for a repro condition.
@sloria Sure. The first result gets focused when the results are returned from backend, ant ONLY if the cursor is inside result pane. Not sure if my explanation could help you.
ONLY if the cursor is inside result pane.
Ah, that's helpful. Perhaps I was unconsciously moving the cursor outside of the result pane before the results came back. I'll keep an eye out if I see the issue again.
Hello! First off, THANK YOU for making such a useful tool. It has significantly improved my workflow!
Feature description
I would like to have the results window automatically be focused after running a search. I figured the following would achieve this, but it does not:
Here's a GIF to demonstrate what I would like:
Is this something that can be configured, or does it necessitate a code change?
Things about your system and environment(请在此填写你的系统信息)
(Everything else: https://github.com/jeremyckahn/dotfiles/blob/master/.vimrc)