mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Fix prev/next route when we're starting on an unsaved route. #743
This commit is contained in:
parent
765335b0da
commit
b0fe0f2a65
@ -487,16 +487,25 @@ impl SavedRoutes {
|
||||
}
|
||||
|
||||
fn prev(&self, current: &str) -> Option<&NamedRoute> {
|
||||
self.routes
|
||||
.range(..current.to_string())
|
||||
.next_back()
|
||||
.map(|pair| pair.1)
|
||||
// Pretend unsaved routes are at the end of the list
|
||||
if self.routes.contains_key(current) {
|
||||
self.routes
|
||||
.range(..current.to_string())
|
||||
.next_back()
|
||||
.map(|pair| pair.1)
|
||||
} else {
|
||||
self.routes.values().last()
|
||||
}
|
||||
}
|
||||
|
||||
fn next(&self, current: &str) -> Option<&NamedRoute> {
|
||||
let mut iter = self.routes.range(current.to_string()..);
|
||||
iter.next();
|
||||
iter.next().map(|pair| pair.1)
|
||||
if self.routes.contains_key(current) {
|
||||
let mut iter = self.routes.range(current.to_string()..);
|
||||
iter.next();
|
||||
iter.next().map(|pair| pair.1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn new_name(&self) -> String {
|
||||
|
Loading…
Reference in New Issue
Block a user