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

[WIP] Create "substring" match type #12616

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MilesCranmer
Copy link

This is a WIP. It does not yet seem to trigger the desired behavior so I am trying to debug this.

Description

Similar behavior to zsh's history-substring-search method, this matching algorithm will check if a given string is contained within the other, regardless of position.

User-Facing Changes

  • This adds the "substring" match type, so users can turn on a history-substring-search

Tests + Formatting

  • These need to be implemented. I wanted to get people's thoughts first as it might change how I need to write the test.

After Submitting

# Description
Similar behavior to zsh's history-substring-search method,
this matching algorithm will check if a given string is contained
within the other, regardless of position.
@MilesCranmer
Copy link
Author

MilesCranmer commented Apr 22, 2024

Actually maybe I'm implementing this in the wrong spot... @fdncred Where is the history up/down prefix matching done?

@MilesCranmer
Copy link
Author

Looks like https://github.com/nushell/reedline/blob/46f410bfdce0b64c3d94fdc0271886f30d64b151/src/history/base.rs#L13 is what is needed in reedline. So just need the right config to enable this?

@MilesCranmer
Copy link
Author

MilesCranmer commented Apr 22, 2024

It basically looks like all we need to do is to set the Reedline object to have its history_cursor field equal to a HistoryCursor object with field query equal to HistoryNavigationQuery::SubstringSearch(String).

So where is the Reedline object created?


Edit: or maybe this has to be done by mapping "up" to ReedlineEvent::HistorySearch??

@fdncred
Copy link
Collaborator

fdncred commented Apr 22, 2024

Usually to implement things like this, it requires a change to reedline and a change to nushell. Following your comments, some of this could already be done (it looks like substring is already in reedline as per your link). You'll have to experiment to see what works.

One way that I test this type of stuff is using the example demo in reedline or setup an additional example in reedline to show how to use your changes.

@MilesCranmer
Copy link
Author

Ok this might take me a while longer to figure out. I'll just mention that if anybody wants to have a go at this instead, please be my guest!

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

2 participants