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

statusline: Add search position #4635

Closed
wants to merge 13 commits into from
Closed

Conversation

sigmaSd
Copy link
Contributor

@sigmaSd sigmaSd commented Nov 7, 2022

hx_sel

@sigmaSd sigmaSd changed the title Pos statusline: Add search position Nov 7, 2022
@kirawi kirawi added A-gui Area: Helix gui improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Nov 7, 2022
// Find all matches in the document
// Then find the current match position inside all matches
// We then render that to the status line by setting editor.search_matches
let all_matches: Vec<_> = regex.find_iter(contents).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little reluctant about this feature in general because it requires collecting all matches in the document. n only needs to find the first match after the start point and N works on a subslice of the document in most cases but with this change, all invocations of n and N find all matches of the pattern across the doc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe all_matches should be cached somewhere so consecutive n N don't need to do a full search

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be cached like this 07c5e9a (I can clanup the code) between consecutive n or N usages.

What do you think? I personally find this feature very useful it feels weird when I'm searching a document and I don't know how many elements ahead there is

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing the matches on the doc (preferrably within SearchPosition) looks good. We should be able to avoid running any regex if we already have the set of matches, and we may want to perform the search async so that we don't block the UI when there are many matches #2811 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged them in one struct. I'll probably need some time to figure out how to make the search async and to use only one regex search, probably we'll need to keep a state in the search like a cursor for where we are at.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-mikedavis can you review/test efdb69a This commit only makes one regex search, if that works and I can clean it up I'll probably tackle async next

Copy link
Contributor Author

@sigmaSd sigmaSd Nov 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed a bug when the register / changes the search needs to be also reset, I can fix that later after your next review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helix-view/src/editor.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
@kirawi
Copy link
Member

kirawi commented Nov 10, 2022

Resolves #2811

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 10, 2022

I think I need to add this #2811 (comment) but I wonder how is that implemented should I put a limit based on contents number of chars: (need to figure how to not land inside Unicode surrogate because that panics)

regex.find_iter(contents [..99999]) and then cap the max number of found items as well just to guarantee thats it's always the same

@the-mikedavis the-mikedavis linked an issue Nov 10, 2022 that may be closed by this pull request
@kirawi
Copy link
Member

kirawi commented Nov 10, 2022

Maybe instead we could have it reflect split_selection instead?

@the-mikedavis
Copy link
Member

Limiting the number of chars found seems unnecessary. To limit to a certain number of results you can use Iterator::take on the iterator produced by Regex:find_iter

@kirawi
Copy link
Member

kirawi commented Nov 12, 2022

What if we instead added an element that showed the selection position?

@kirawi kirawi closed this Nov 12, 2022
@kirawi kirawi reopened this Nov 12, 2022
@kirawi
Copy link
Member

kirawi commented Nov 12, 2022

Misclick.

@the-mikedavis
Copy link
Member

What if we instead added an element that showed the selection position?

Do you mean the line-number/column of the current match?

@archseer archseer removed the A-gui Area: Helix gui improvements label Dec 2, 2022
@zummenix
Copy link
Contributor

I would like to have this feature. Sometimes I need it really bad, so bad that I've implemented it in my fork hoping to open a PR but then noticed this :)

zummenix@e1ccd0c

Differences are that in my implementation I don't keep state and use the status line to display current match and total number of matches. Works fast on sane documents, haven't checked it on big.

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Apr 19, 2023

@zummenix feel free to open another PR, I don't think I''m going to have time to finish this

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Apr 19, 2023

The point of keeping state is to not search the whole document

@zummenix
Copy link
Contributor

The point of keeping state is to not search the whole document

I understand this is an optimization. But maybe it works fast enough that it doesn't matter. One problem I see with keeping state is that there should be clear invalidation points like changing a search query or changes in a document, perhaps something else.

@pascalkuthe
Copy link
Member

closing this one out as stale, thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show match index and number of matches when searching
6 participants