Skip to content
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

ivy-resume restarts at the beginning of counsel-ag and counsel-rg #1095

Closed
eflanigan00 opened this issue Jul 5, 2017 · 23 comments
Closed

ivy-resume restarts at the beginning of counsel-ag and counsel-rg #1095

eflanigan00 opened this issue Jul 5, 2017 · 23 comments

Comments

@eflanigan00
Copy link

@eflanigan00 eflanigan00 commented Jul 5, 2017

I type counsel-ag, type some characters then scroll down a few lines and pick a selection. When I invoke ivy-resume I get the same character search properly but the selected line starts back at the beginning of the selection list instead of resuming from my last selection.

@eflanigan00 eflanigan00 changed the title ivy-resume starts at the beginning of counsel-ag ivy-resume restarts at the beginning of counsel-ag Jul 5, 2017
@eflanigan00 eflanigan00 changed the title ivy-resume restarts at the beginning of counsel-ag ivy-resume restarts at the beginning of counsel-ag and counsel-rg Aug 13, 2017
@amosbird
Copy link
Contributor

@amosbird amosbird commented Nov 10, 2017

+1. It seems this is due to :dynamic-collection t.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Nov 10, 2017

This is indeed due to :dynamic-collection. When you resume, you can't be sure that the candidate that you selected before even exists. And then the candidates start coming it asynchronously. This is a problem: suppose you had selected candidate "foo", 101st on the list of 2000. When you resume, and the first chunk of 50 candidates comes in, what should be selected?

I'll think about making some improvement here, but it's not straightforward.

@neojski
Copy link
Contributor

@neojski neojski commented Jan 17, 2018

Not sure it's because of :dynamic-collection. When I resume SPC f f it doesn't seem to highlight the previous search either. @abo-abo, is it supposed to work or it's not supported?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jan 17, 2018

@neojski counsel-find-file is supported, if that's what you mean.

@hisnawi
Copy link

@hisnawi hisnawi commented Jan 17, 2018

Any possibility this issue gets resurrected?
Seems like a very important feature to have when the search results are in the hundreds.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jan 18, 2018

@hisnawi The issue isn't closed. Anyone is free to contribute.

Just understand that this isn't an easy fix, at least as far as I can see. I estimate this issue at 1-2 hours of uninterrupted time and low priority; so it won't get done any time soon unless someone else steps up with a contribution.

@hisnawi
Copy link

@hisnawi hisnawi commented Jan 18, 2018

Thanks for the response, I am a beginner when it comes to lisp otherwise I would have given it a go. But what I noticed is that helm already has this feature and it is very similar to ivy in terms of showing results dynamically. Wouldn't it be possible to leverage some of their code to integrate it in ivy?

It maybe a completely different issue in ivy I am just speculating.

@neojski
Copy link
Contributor

@neojski neojski commented Jan 23, 2018

@neojski counsel-find-file is supported, if that's what you mean.

I just tried with make plain version and it doesn't seem to work, i.e. I did:

  1. C-x C-f C-n C-g (select ..)
  2. M-: (ivy-resume) ret

Expected: .. is selected
Result: . is selected

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jan 23, 2018

@neojski Thanks, I can reproduce it now.

@neojski
Copy link
Contributor

@neojski neojski commented Feb 20, 2018

@abo-abo, you expected this to work. What part of ivy code was supposed to be responsible for this? If you pointed me to the right place in the source code I could try to fix it.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Feb 21, 2018

@neojski You can look at the source code of ivy-resume. The interesting part is:

:preselect (ivy-state-current ivy-last)

So there are two things to check:

  • (ivy-state-current ivy-last) is the right value
  • ivy-read using it does the right thing

@ericdanan
Copy link
Contributor

@ericdanan ericdanan commented Mar 20, 2018

In ivy-resume I don't see

:preselect (ivy-state-current ivy-last)

but

:preselect (unless (eq (ivy-state-collection ivy-last)
                       'read-file-name-internal)
             (regexp-quote ivy--current))

which seems to be there since commit 84e20a3 . So it seems to be on purpose that preselect is not set for counsel-find-file but I don't know why.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Mar 20, 2018

So it seems to be on purpose that preselect is not set for counsel-find-file but I don't know why.

I can't tell from the message as well. Maybe this has something to do with TRAMP. I think I'll just revert it to simplify the code.

abo-abo added a commit that referenced this issue Mar 20, 2018
@ericdanan
Copy link
Contributor

@ericdanan ericdanan commented Mar 20, 2018

I just tested and it works if ivy-state-current is a file but not if it is a directory. Maybe something going on in ivy-reset-state.

Neither does it work if I navigate to another directory before exiting with C-g, the directory I navigated to is not remembered. Perhaps ivy--cd should update ivy-state-directory.

Sorry that I can't investigate more at the moment.

@ericdanan
Copy link
Contributor

@ericdanan ericdanan commented Mar 26, 2018

Indeed I was able to make it work (I think) by modifying ivy--reset-state and ivy--cd. See #1508.

@neojski
Copy link
Contributor

@neojski neojski commented May 19, 2018

I thin this issue is not actually fixed for counsel-ag or counsel-rg.

@peterwvj
Copy link

@peterwvj peterwvj commented May 27, 2019

I also experience this issue with counsel-ag.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented May 27, 2019

@neojski @peterwvj I reopen this issue, since the preselect is not yest fixed for dynamic collections like counsel-ag.

@abo-abo abo-abo reopened this May 27, 2019
@abo-abo abo-abo closed this in d00b4cd Jun 28, 2019
abo-abo added a commit that referenced this issue Jun 28, 2019
If `dynamic-collection' is set, Ivy will wait until the first chunk of
candidates has been received before selecting the preselected
candidate.

Fixes #1095
Fixes #2112
@peterwvj
Copy link

@peterwvj peterwvj commented Jul 1, 2019

Thanks a lot for working on this @abo-abo

So it seems like ivy-resumeis now able highlight the previously selected line, assuming that the search results produced using counsel-ag did not change in the meantime. Am I correct? This works very well assuming that you don't need to edit the search results.

For comparison helm-ag will by fault "freeze" the search results making it possible to resume to the previously highlighted line. Obviously this is easily done because helm-ag does not use a dynamic collection like counsel-ag does. I can see advantages to both approaches. However, I was wondering if it would be possible to configure counsel-ag to use a collection that enables a helm-ag-like behavior. I recently switched from helm to ivy so please bear with me if there's an obvious solution to this.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jul 1, 2019

@peterwvj I don't understand what "freeze" means. Please open a new issue with a step-by-step scenario.

@peterwvj
Copy link

@peterwvj peterwvj commented Jul 1, 2019

To clarify, helm-ag does not use dynamic collections. In consequence, the helm-ag search results are just produced ones, and not automatically updated when you call helm-resume.

So if you perform a search (by calling helm-ag), then navigate to the location of one your matches, edit that line, and call helm-resume then helm takes you back to the exact same line. This is always possible because the search results do not get updated. Not even if your edits would somehow "invalidate" the search results.

Does this make sense?

So my question is: would it be possible to easily configure counsel-ag to behave in this way?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jul 1, 2019

So my question is: would it be possible to easily configure counsel-ag to behave in this way?

Yes. If you do C-c C-o (ivy-occur), your matches will be saved to a new buffer that represents the current search. You can have as many buffers as you like.
The results that they contain may become stale, which will make f go to a stale line number.
But you can refresh each buffer with g to make the results non-stale again.

@peterwvj
Copy link

@peterwvj peterwvj commented Jul 1, 2019

Great, this is exactly what I need! Thanks a lot for explaining this!

astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
If `dynamic-collection' is set, Ivy will wait until the first chunk of
candidates has been received before selecting the preselected
candidate.

Fixes abo-abo#1095
Fixes abo-abo#2112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants