Fix for handling multiple tab autocomplete attempts #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this attempting to fix?
Prior to this PR, a user's input was taken into account only for the first autocompletion pass through; after which prompt-sync would fall back to cycling through the entire possible data set provided by the user, regardless of whether the initial search string yielded multiple possible autocomplete results.
Additionally, any subsequent autocomplete attempts would yield results from anywhere within the new result list, not the start.
How does this fix the problem?
This PR splits the responsibilities of the autocomplete search string and the main output string between two variables.
autoCompleteSearchTerm
allows users to cycle through the results of the current search, whilestr
allows current selection and terminal output to stay up-to-date as it did before.Hitting any other key after the tab would clear the current search state.
Testing / Example Case
Simple demo program to demonstrate the fix:
In either version, running the program and entering "a", followed by TAB would yield the string: "Apple".
Prior to the fix, subsequent TAB inputs would yield the following results:
After the fix, subsequent tab inputs yield all a-strings:
Demo
Before
After