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

Make editor remember the latest search register #5244

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

xJonathanLEI
Copy link
Contributor

Resolves #5112.

This PR makes changes to the behavior of search commands:

  • The editor now remembers the search register used to kick start a search/rsearch/global_search command;
  • search_next, search_prev, extend_search_next, and extend_search_prev now uses the search register to continue the search;
  • search_selection now uses the selected register. It also updates the search register;
  • make_search_word_bounded defaults to using the search register to make the search_selection-make_search_word_bounded flow more ergonomic, while also accepting register selection.

Overall, this PR should make the whole family of search commands play more nicely with register selection.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Dec 24, 2022
@xJonathanLEI xJonathanLEI changed the title Make search commands respect register selection Make editor remember the latest search register Aug 13, 2023
@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Aug 13, 2023

Update:

Recent changes in the editor fixed the part where commands do not respect immediate register selection (i.e. "bn now uses register b as expected). However, the UX is still bad as this requires the user to enter the "b prefix every time to navigate through the search results.

That's why this PR is still relevant IMO, as the 2nd part of the PR is to make the editor remember the latest register used to kick off a search, and uses that by default unless a prefix is explicitly specified. In this case users can drop the prefix and simply press n to navigate.

Also update the PR title to better reflect the only part left for this PR.

pascalkuthe
pascalkuthe previously approved these changes Aug 14, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Aug 14, 2023

yeah I think this is a nice QOL improvement and makes sense. Implementation is pretty small/unintrusive too 👍

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

This seems potentially too sticky to me: / is meant to be the default when you don't provide a register but this change makes any register that you select the default until you explicitly select another one. I would prefer to see this as last_search_register: Option<char> on the editor. The functions that start searches like searcher and search_selection would set/clear the field if a register is/isn't selected while the functions that continue a search like search_next_or_prev_impl and make_search_word_bounded would only read from the field.

@xJonathanLEI
Copy link
Contributor Author

this change makes any register that you select the default until you explicitly select another one

Not really though? If you start a new search with just / (no explicit prefix), it changes back to the / register. See this line, which is what starts a search. It doesn't even read from search_register.

I too agree that if it were that sticky it's a problem, but that's not the case here. I also just tested my branch and it's indeed working as expected (i.e. reverts back to / when performing a new search without prefix).

@the-mikedavis
Copy link
Member

Ah yep I see now. Let's rename it to last_search_register though, the current name is confusing to me.

@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Aug 14, 2023

Renamed the field the last_search_register as suggested.

(Oops. Maybe I shouldn't have rebased... Now the compare button is pretty much useless)

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

Diff is small enough to review quickly so no worries
:) Maybe one more thing: we could move last_search_register to editir.registers. This avoids adding more field to Editor

@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Aug 14, 2023

Sure thing! But do you mean making this a pub field of Registers? Looks like that struct does not have any public field yet. Should I make it the first? Or should I keep it private but expose a method with the same name?

Edit: I pushed the pub version optimistically.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

A public field is probably fine in this case 👍 I don't think it makes sense to encapsulate here. For me it's just about bundling related fields together instead of making Editor the kitchen sink for everything

@the-mikedavis the-mikedavis merged commit 3a162e2 into helix-editor:master Aug 14, 2023
6 checks passed
@xJonathanLEI xJonathanLEI deleted the dev/search_register branch August 15, 2023 01:40
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make search commands respect the register prefix?
4 participants