-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Made the list of exercises searchable, ref #2093 #2098
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4fd295
added a way to search through list, ref #2093
frroossst e1e316b
Merge branch 'main' of https://github.com/frroossst/rustlings
frroossst e966235
Merge branch 'rust-lang:main' into main
frroossst 388f8da
removed debug statements
frroossst 92a1214
passes clippy lints
frroossst 44ab7f9
Merge branch 'main' of https://github.com/frroossst/rustlings
frroossst 547a9d9
escape/enter no longer exits the list, exits only the search
frroossst abf1228
search now filters the list first
frroossst 3125561
Merge branch 'rust-lang:main' into main
frroossst 7149426
fixed clippy lints
frroossst 1e7fc46
Merge branch 'main' of https://github.com/frroossst/rustlings
frroossst 948e16e
moved continue to end of if-block
frroossst fea917c
removed unnecessary update_rows() call and minor refactoring
frroossst 47148e7
replaced enumerate() with position(); converted select_if_matches_sea…
frroossst e9879ea
merge of origin/main
frroossst f463cf8
passes clippy lints and removed extra code from the merge
frroossst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ pub struct ListState<'a> { | |
term_width: u16, | ||
term_height: u16, | ||
show_footer: bool, | ||
pub search_query: String, | ||
} | ||
|
||
impl<'a> ListState<'a> { | ||
|
@@ -76,6 +77,7 @@ impl<'a> ListState<'a> { | |
term_width: 0, | ||
term_height: 0, | ||
show_footer: true, | ||
search_query: String::new(), | ||
}; | ||
|
||
slf.set_term_size(width, height); | ||
|
@@ -345,6 +347,37 @@ impl<'a> ListState<'a> { | |
Ok(()) | ||
} | ||
|
||
pub fn apply_search_query(&mut self) { | ||
self.message.push_str("search:"); | ||
self.message.push_str(&self.search_query); | ||
self.message.push('|'); | ||
|
||
if self.search_query.is_empty() { | ||
return; | ||
} | ||
|
||
let idx = self | ||
.app_state | ||
.exercises() | ||
.iter() | ||
.filter(|exercise| match self.filter() { | ||
Filter::None => true, | ||
Filter::Done => exercise.done, | ||
Filter::Pending => !exercise.done, | ||
}) | ||
.position(|exercise| exercise.name.contains(self.search_query.as_str())); | ||
|
||
match idx { | ||
Some(exercise_ind) => { | ||
self.scroll_state.set_selected(exercise_ind); | ||
} | ||
None => { | ||
let msg = String::from(" (not found)"); | ||
self.message.push_str(&msg); | ||
frroossst marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to create a |
||
} | ||
} | ||
} | ||
|
||
// Return `true` if there was something to select. | ||
pub fn selected_to_current_exercise(&mut self) -> Result<bool> { | ||
let Some(selected) = self.scroll_state.selected() else { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to draw here to remove the search query. I will test it.