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

Search in selections #10831

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kshokhin
Copy link

Release Notes:

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 22, 2024
@kshokhin
Copy link
Author

kshokhin commented Apr 22, 2024

Hello, Zed team!

Still WIP, couple of questions here:

  1. Currently one of the available icons is used for the button. What is the workflow to get the proper icon? I don't think I'm able to draw it myself
  2. Current implementation launches searches in all selections concurrently. Is it ok, or a straightforward loop over the search ranges, like the search is implemented for buffer excerpts, is more preferable?

Things TBD:

  1. Remove auto-filling of the search editor with the selected content. Though, I'm not quite sure, what the exact solution should be here - do not auto-fill if multiple lines are selected?
  2. Selections are cleared on every matches set update, which is kind of annoying, when I'm trying to search in a selection. So I'm thinking of disabling this behaviour, when "search-in-selections" mode is toggled. Please, share your thoughts if you think of anything better.

@ConradIrwin ConradIrwin self-assigned this Apr 26, 2024
@ConradIrwin
Copy link
Collaborator

@kshokhin Hopefully @iamnbutler can help with getting the icon right. You might be able to reuse "quote" for now (as that's similar to VScode's icon; though pretty hard to interpret if you are not used to it :D) or "filter"? Either way we'll need a good tooltip.

I'd love to pair with you on this as that's probably more effective than me guessing at how it should work in a comment :D – if you have time let's chat next week: https://calendly.com/conradirwin/pairing.

We're also running into some overlap with @cthulhua's work on #10709; so I may need to reconsider what I put there too...

Some thoughts in no particular order:

  • I agree with not prefilling the search bar with a multiline query.
  • I am not sure that the default when opening a search with a multiline selection should be to "find within selection". I think it makes sense to use a separate action for this.
  • When you are in a search with a specific range, we should store that range on the editor so it can highlight them using editor.highlight_background (or possibly highlight_rows, but it seems "neater" to preserve the exact selections). This will require some changes to the SearchableItem trait, but will at least mean that you can still use the editor as normal without affecting your search range.
  • When you are in this mode, it makes sense to show an indicator in the search bar that "searching is restricted to a range". Though that indicator should be outside of the text box (and hidden in narrow_mode). Clicking on the indicator (or closing search) would clear the ranges.
  • (Bikeshedding...) The search bar can be used at quite small sizes, and I'd like to avoid adding an extra button when you're not in this (relatively uncommon) mode. Maybe we could make the entry point to this in the editor when you have a multiline selection?
Screenshot 2024-04-25 at 20 06 29 * Also happy to leave this for later work, as that is significant scope creep!

@JosephTLyons
Copy link
Contributor

JosephTLyons commented Apr 26, 2024

This PR is extremely useful when you are aware that theres a secondary way to do editor: select all matches, which is search: select all matches. editor: select all matches is incredibly powerful, but you are stuck with getting everything in the entire document. Being able to highlight a block, toggle this selection mode, and then run search: select all matches is huge!

@JosephTLyons
Copy link
Contributor

If you are able to get this to search inside of multiple disjoint selection, that would be killer.

@ConradIrwin
Copy link
Collaborator

In #10709 we ended up allowing the editor to store "search within" ranges (though in that case we clear them as soon as we're done).

I think we can build on that to make this work without having to be so careful about the selection.

@ConradIrwin
Copy link
Collaborator

@kshokhin How're you getting on with this? Happy to take a look if you think it's ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants