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

New multi-selection UI #163

Merged
merged 4 commits into from Jul 8, 2021
Merged

New multi-selection UI #163

merged 4 commits into from Jul 8, 2021

Conversation

bdarcus
Copy link
Contributor

@bdarcus bdarcus commented Jul 5, 2021

Screenshot from 2021-07-06 14-32-22

This implements the ideas in #160, as a means to fix various problems with CRM for this package.

The key UI thing to realize is you don't really want to use TAB here; just RET.

Also, deselect works the same as select.

I added a defcustom for this, but I have set it to t here, as something like this UI is always what I had in mind, so if this doesn't work well, I may need to explore other alternatives (shorter candidate strings, avoiding CRM in general, focusing on Embark more for acting on multiple candidates, etc.).

I've also added some minimal documentation.

As always, you can test by running the test/run.sh script.

Note: the screenshot is with the vertico-crm prototype version of this.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 5, 2021

@minad @oantolin - the big, and only significant, issue ATM is Embark doesn't work correctly.

The menu is accessible as expected, but whether one or multiple candidates, I get no results.

Is this because simple-crm is using CR, while I have existing code like this?

(interactive (list (bibtex-actions-read :rebuild-cache current-prefix-arg)))

Edit: I'll experiment with moving list to bibtex-actions-read.

@minad
Copy link
Contributor

minad commented Jul 5, 2021

Ouch, this is a serious issue - since consult-completing-read-multiple/simple-crm calls completing-read in a loop we break the Embark minibuffer injection. I hadn't thought of this 😢

@andersjohansson
Copy link
Contributor

Quickly tried it out and really like it! Hope the issues are solvable.

@minad
Copy link
Contributor

minad commented Jul 5, 2021

We could solve it by checking manually for the embark--target (if fboundp) in simple-crm/consult-completing-read-multiple. This is not ideal but at least ensures that Embark injection works. @oantolin Do you have a better idea?

@minad
Copy link
Contributor

minad commented Jul 5, 2021

@bdarcus Given that everyone seems to like the UI I may reconsider adding consult-completing-read-multiple to consult in the generic form with embark support. It has the few issues (flicker, double-RET, potential sorting problems) as we discussed but the cost/benefit ratio is not bad, in particular since it is compatible with different UIs. Let's gather a bit more feedback :)

The latest consult version is here: https://github.com/minad/consult/blob/3d28108d841a698bf2ec42e32fa954adbb88a87a/consult.el#L2154-L2226

@oantolin
Copy link
Contributor

oantolin commented Jul 5, 2021

Do you have a better idea?

I don't know if this is better, but it's at least different: We could arrange for a target finder that if simple-crm is running returns a target that is a list of selected items, not a string. And we could modify Embark so that if the target is a non-empty list, instead of injection the command gets called with the list as argument, whether or not the action is a command.

@minad
Copy link
Contributor

minad commented Jul 5, 2021

Well but this would require the command to take a list as argument. Furthermore I am not happy with the idea of list targets. When acting on the candidates in CRM you still act on single candidates (single string). I would not overcomplicate things here - it is sufficient if we ensure that the single candidate injection works since this allows using simple-crm-based commands as embark actions.

@oantolin
Copy link
Contributor

oantolin commented Jul 5, 2021

Well, without a special target finder for simple-crm, running embark-act from it will just pick up the single candidate for the current run of completing-read, no? So we still need someway to extract the selected candidates from simple-crm and it might as well be as a list (I guess the other option is as a single string with separators).

@minad
Copy link
Contributor

minad commented Jul 5, 2021

Okay, that's right. We would not pick up the selected items, only the current item. If we would want to support this we would need a special target finder. But then I would prefer if the embark action is called once for each item in the list.

I only oppose adding another Embark calling convention for handling a list. Adding a special CRM target finder returning a list seems okay conceptually. Alternatively one injects the list separated by crm-separator, this would also be acceptable but would exclude using CR actions from CRM.

@minad
Copy link
Contributor

minad commented Jul 6, 2021

Current consult-completing-read-multiple version: https://github.com/minad/consult/blob/1b2d93cad8a34456d2aad9ad892ce2b41debbad6/consult.el#L2154-L2248

Does not support Embark yet, still have to figure out how to do this. Besides that, I think it works well enough.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 6, 2021

@mohkale @apc - can you give this a test and give us feedback?

@minad - is it also feasible to use the consult version as I do here, in addition to the advice approach?

@minad
Copy link
Contributor

minad commented Jul 6, 2021

When the consult version gets merged, my recommendation is to not add anything special here. Just use completing-read-multiple and be done :) This way the user gets a consistent CRM UI for every command.

Take a look at the current version in minad/consult#352. Main problem is Embark. This is certainly fixable but may require some Embark detection (gluing code).

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 6, 2021

When the consult version gets merged, my recommendation is to not add anything special here. Just use completing-read-multiple and be done :)

Beyond the big embark issue, I guess one little issue remains: the filtering for pdf, etc.

Still the case that initial-input won't work? If yes, do I want to add a predicate for the pre-filtering?

@minad
Copy link
Contributor

minad commented Jul 6, 2021

I guess one little issue remains: the filtering for pdf, etc.
Still the case that (initial-input) won't work? If yes, do I want to add a predicate for the pre-filtering?

Initial input is completely treated as candidates. It is not treated as a filter string. Maybe that is not the best behavior. I could tweak it as follows:

  1. Split the initial-input by crm-separator
  2. Use the butlast items as selected candidates
  3. Use the last item either as selected candidate or as filter string, depending on if the string is part of the candidate list

However the filter string should probably still be used only once, since this is more aligned with how completing-read-multiple by default works. Your has:pdf filter also does not work correctly with the default crm implementation, since it only applies to the first candidate. After pressing TAB the has:pdf filter is lost. Therefore I proposed to use a predicate instead or even filter the list of candidates before passing them to completing-read-multiple.

If you add your own implementation here, you can of course special case this somehow, but I think it would be better if you use a common CRM implementation, since this potentially leads to a more consistent UI.

Another option we could discuss is the following:

  1. consult-completing-read-multiple treats initial-input completely as candidates as it does now
  2. Add a variable consult-crm-initial-input, which you can let bind dynamically, such that it is always used as a filter. Of course this would only be effective when the user has configured to use consult-completing-read-multiple.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 6, 2021

I'll defer to you on what's the best general approach for consult-read-multiple.

But on this:

Therefore I proposed to use a predicate instead or even filter the list of candidates before passing them to completing-read-multiple.

Is there some downside to using a predicate here?

I have a cache of all the candidates, where some commands need to get different subsets.

There is some value in being able to return to the full set, as we can now with initial-input, but that's probably not necessary.

@minad
Copy link
Contributor

minad commented Jul 6, 2021

Is there some downside to using a predicate here?
I have a cache of all the candidates, where some commands need to get different subsets.

The predicate will be a bit more expensive since it filters the candidates every time. But the cost will probably be small. The downside of predicate/filter vs your current "has:pdf" approach is that the user cannot remove the filter. In contrast with "has:pdf" the user can delete this filter string in order to see all candidates. Is that important/desired?

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 6, 2021

The downside of predicate/filter vs your current "has:pdf" approach is that the user cannot remove the filter. In contrast with "has:pdf" the user can delete this filter string in order to see all candidates. Is that important/desired?

Yes, it is. That's why we used initial-input (and why @mohkale was experimenting with Consult narrowing).

I just don't know how important that flexibility is; it's possible not very.

If I don't need to make that choice now, I would probably leave things as is.

But the intial-input would need to consistently apply to all candidate selections for it to work as we expected. As you know, it doesn't in CRM.

minad/vertico#59

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 6, 2021

consult-completing-read-multiple is now merged. I'll adjust this accordingly.

minad/consult#352
minad/vertico#74

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 7, 2021

So I dropped the initial commit here, and replaced with a test script modified to use consult-completing-read-multiple.

It doesn't currently work locally for me, but I think the problem is something other than what I committed.

Next I'll update the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants