mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
fix(TUI): Fixed panic when changing order of items in TableView before the number of items in the table is reduced (#3160)
This commit is contained in:
parent
b5f73b6aab
commit
39af7fa202
1 changed files with 3 additions and 3 deletions
|
@ -492,7 +492,7 @@ impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
|
|||
/// Returns the index of the currently selected item within the underlying
|
||||
/// storage vector.
|
||||
pub fn item(&self) -> Option<usize> {
|
||||
if self.items.is_empty() {
|
||||
if self.items.is_empty() || self.focus > self.rows_to_items.len() {
|
||||
None
|
||||
} else {
|
||||
Some(self.rows_to_items[self.focus])
|
||||
|
@ -604,7 +604,7 @@ impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
|
|||
|
||||
fn sort_items(&mut self, column: H, order: Ordering) {
|
||||
if !self.is_empty() {
|
||||
let old_item = self.item().unwrap();
|
||||
let old_item = self.item();
|
||||
|
||||
let mut rows_to_items = self.rows_to_items.clone();
|
||||
rows_to_items.sort_by(|a, b| {
|
||||
|
@ -616,7 +616,7 @@ impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
|
|||
});
|
||||
self.rows_to_items = rows_to_items;
|
||||
|
||||
self.set_selected_item(old_item);
|
||||
old_item.map(|o| self.set_selected_item(o));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue