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()
}

View File

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

View File

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

View File

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