diff --git a/src/components/history.rs b/src/components/history.rs index 2d90884..e04e9ee 100644 --- a/src/components/history.rs +++ b/src/components/history.rs @@ -113,15 +113,16 @@ impl History { } fn select_latest(&mut self) -> Result<()> { - for (i, item) in self.items.iter().enumerate() { + let index_to_select = self.items.iter().enumerate().find_map(|(i, item)| { let item = item.borrow(); if !item.is_running { - self.state.select(Some(i)); - return Ok(()); + Some(i) + } else { + None } - } + }); - Ok(()) + self.select(index_to_select) } fn select(&mut self, index: Option) -> Result<()> {