Fix prev/next route when we're starting on an unsaved route. #743

This commit is contained in:
Dustin Carlino 2021-09-17 12:36:14 -07:00
parent 765335b0da
commit b0fe0f2a65

View File

@ -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 {