return position as the option

This commit is contained in:
yggverse 2024-12-18 09:36:42 +02:00
parent 6203ef5b28
commit 467a287468
4 changed files with 14 additions and 10 deletions

View File

@ -95,7 +95,7 @@ impl Navigation {
} }
} }
pub fn position(&self) -> usize { pub fn position(&self) -> Option<usize> {
self.model.borrow().position() self.model.borrow().position()
} }

View File

@ -24,7 +24,7 @@ impl<T> Model<T> {
self.vector.get(self.cursor.as_index()) self.vector.get(self.cursor.as_index())
} }
pub fn position(&self) -> usize { pub fn position(&self) -> Option<usize> {
self.cursor.as_position() self.cursor.as_position()
} }

View File

@ -35,7 +35,11 @@ impl Cursor {
} }
} }
pub fn as_position(&self) -> usize { pub fn as_position(&self) -> Option<usize> {
self.current if self.current > 0 {
Some(self.current)
} else {
None
}
} }
} }

View File

@ -22,13 +22,13 @@ impl Result {
// Actions // Actions
pub fn update(&self, current: usize, total: usize) { pub fn update(&self, current: Option<usize>, total: usize) {
if total > 0 { if total > 0 {
if current > 0 { match current {
self.label Some(position) => self
.set_label(&format!("{current} of {total} matches")); .label
} else { .set_label(&format!("{position} of {total} matches")),
self.label.set_label(&format!("{total} matches")); None => self.label.set_label(&format!("{total} matches")),
} }
self.label.remove_css_class("error"); self.label.remove_css_class("error");
} else { } else {