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

Selection-constrained search/replace #8617

Open
1 task done
zambetti opened this issue Feb 29, 2024 · 8 comments
Open
1 task done

Selection-constrained search/replace #8617

zambetti opened this issue Feb 29, 2024 · 8 comments
Labels
enhancement [core label] good first issue Issue suitable for first-time contributors search / project search Feedback for in-file search, multi-buffer global search, etc

Comments

@zambetti
Copy link

zambetti commented Feb 29, 2024

Check for existing issues

  • Completed

Describe the feature

It seems that, as it is now, Zed can only perform search/replace on an entire document, and there is no way to constrain search/replace to only the selected text.

When you click the magnifying glass while text is selected, it assumes that you are searching for the selected text. This assumption might speed up some scenarios, but it necessitates that all searching is to be done for the entire document. This limits the value of "replace all".

Link to discussion on this topic.

If applicable, add mockups / screenshots to help present your vision of the feature

A proposed modification to the existing search/replace function is:

  1. Remove auto-fill of selected text in search field when opening "Buffer Search" via clicking on magnifying glass or via cmd-E. Auto-fill of search field would still happen as it does today with cmd-F.

  2. Add toggle button for "Selected text only" to the "Buffer Search" UI

@zambetti zambetti added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Feb 29, 2024
@Moshyfawn Moshyfawn added search / project search Feedback for in-file search, multi-buffer global search, etc and removed triage Maintainer needs to classify the issue labels Feb 29, 2024
@JosephTLyons JosephTLyons removed the admin read Pending admin review label Feb 29, 2024
@JosephTLyons
Copy link
Contributor

JosephTLyons commented Feb 29, 2024

Not sure if there is anything salvagable this long after the fact, but an older employee had begun work on this here:

Might be useful to someone else wanting to work on this. Adding the good first issue simply because that prior PR might have enough info to make this more trivial to add.

@JosephTLyons JosephTLyons added the good first issue Issue suitable for first-time contributors label Feb 29, 2024
@timcki
Copy link

timcki commented Feb 29, 2024

Hi! I'd like to try implementing this feature if @zambetti hasn't started work on it yet (:

@hferreiro
Copy link
Contributor

Currently, when multiple lines are selected, only the first one is auto-filled, so what about only using auto-fill when the selection doesn't span over more than 1 line?

@zambetti
Copy link
Author

zambetti commented Mar 1, 2024

Currently, when multiple lines are selected, only the first one is auto-filled

@hferreiro: I just tried this. if you select multiple lines, and open Buffer Search via cmd-F, the auto-filled search field looks like it only has one line, but the remaining lines and horizontally-clipped text can be seen via two-finger scroll&pan (I'm using Zed Preview 0.125.0).

Your comment makes me think that the search field (and replace field) in Buffer Search being only a single line high is perhaps a place for possible UI improvement. When containing multiline content, the fields (and panel) could grow in height to show two lines, indicating that there is more to see and that the panel is growable. That with the ability to click&drag the border of the Buffer Search pane downward to reveal more lines in both the search and replace fields would make it friendlier for multiline work. This kind of UI improvement is likely beyond the scope of this ticket though.

Hi! I'd like to try implementing this feature if @zambetti hasn't started work on it yet (:

Hi @timcki, it's great that you're up for taking a shot at this with the talented Zed team. I hope to one day have the chops to be a contributor, still in the process of learning Rust.

@hshreekar
Copy link
Contributor

Hey, can i try to implement this feature (specifically fetaure 2)?.

I have gone through the linked PR , and some of the code of the Search functionality. I am gonna try to explain what I understood from the code, any guidance on my understanding or documentation about it would be helpful.

crates/search/src/search.rs - This contains the searchOptions struct which is needed for SearchQuery struct which is in (crates/project/src/search.rs)

The Changes in search.rs are just adding a field named ToggleSelection and defining the icon etc,etc.
My understanding is that crates/search/src/search.rs is intended to be used by extending the SearchOptions and does not contain the search functionality, the main functionality that needs to be changed is in crates/search/buffer_search.rs,

I have added Some screenshots. The first file is just the search.rs in project crate
image

This screenshot is of project search in search crate, i dont think i will have to modify this ? (This is just to match paths ?? )
image

and for the last file, buffer_search in search crate, this is where i need to understand the flow the most. Buffer Search has an active query field , which calls find_matches on it and i cant seem to understand the flow from there. :(
image

I am sorry for tagging you but any help would be greatly appreciated @JosephTLyons . Thanks in advance. And sorry for any rude behaviour and for such a large comment

@Anthony-Eid
Copy link
Contributor

@hshreekar I just started working on this issue, do you want to collaborate on it together?

@hshreekar
Copy link
Contributor

Sure @Anthony-Eid. Would love to colloborate with you on this issue

@Anthony-Eid
Copy link
Contributor

I'm available this week or next week to collaborate on it with you. On you on the discord? We could figure out a time for us to hope on a call together there.

ConradIrwin added a commit that referenced this issue Jun 5, 2024
Release Notes:

- Adding [#8617 ](#8617)

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] good first issue Issue suitable for first-time contributors search / project search Feedback for in-file search, multi-buffer global search, etc
Projects
None yet
Development

No branches or pull requests

7 participants