mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 11:16:03 +00:00
Letter-search in SelectView wraps back
This commit is contained in:
parent
c8b2bc943d
commit
a30a77f39b
@ -117,11 +117,15 @@ impl <T> View for SelectView<T> {
|
|||||||
Event::KeyEvent(Key::End) => self.focus = self.items.len()-1,
|
Event::KeyEvent(Key::End) => self.focus = self.items.len()-1,
|
||||||
Event::CharEvent(c) => {
|
Event::CharEvent(c) => {
|
||||||
// Starting from the current focus, find the first item that match the char.
|
// Starting from the current focus, find the first item that match the char.
|
||||||
if let Some((i,_)) = self.items.iter().enumerate()
|
// Cycle back to the beginning of the list when we reach the end.
|
||||||
|
// This is achieved by chaining twice the iterator
|
||||||
|
let iter = self.items.iter().chain(self.items.iter());
|
||||||
|
if let Some((i,_)) = iter.enumerate()
|
||||||
.skip(self.focus+1)
|
.skip(self.focus+1)
|
||||||
.find(|&(_,item)| item.label.starts_with(c))
|
.find(|&(_,item)| item.label.starts_with(c))
|
||||||
{
|
{
|
||||||
self.focus = i;
|
// Apply modulo in case we have a hit from the chained iterator
|
||||||
|
self.focus = i % self.items.len();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => return EventResult::Ignored,
|
_ => return EventResult::Ignored,
|
||||||
|
Loading…
Reference in New Issue
Block a user