list nav: catch some out of bounds errors
This commit is contained in:
parent
4e02b41a77
commit
507887535f
1 changed files with 66 additions and 50 deletions
|
@ -106,6 +106,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
TreeNavResult::Continue
|
||||
}
|
||||
_ => {
|
||||
if self.data.len() > 0 {
|
||||
let idx = crate::modulo(new_cur.tree_addr[0], self.data.len() as isize);
|
||||
|
||||
self.cursor.set(ListCursor {
|
||||
|
@ -120,6 +121,9 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
leaf_mode: new_cur.leaf_mode,
|
||||
tree_addr: new_cur.tree_addr[1..].iter().cloned().collect(),
|
||||
});
|
||||
} else {
|
||||
self.cursor.set(ListCursor::home());
|
||||
}
|
||||
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
|
@ -176,7 +180,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
+ if cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 })
|
||||
{
|
||||
self.cursor.set(ListCursor {
|
||||
mode: cur.leaf_mode,
|
||||
mode: if self.data.len() == 0 { ListCursorMode::Insert } else { cur.leaf_mode },
|
||||
idx: Some(cur.tree_addr[0] + direction.x)
|
||||
});
|
||||
TreeNavResult::Continue
|
||||
|
@ -189,6 +193,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
depth => {
|
||||
// nested
|
||||
|
||||
if cur.tree_addr[0] < self.data.len() as isize {
|
||||
let item = self.data.get_mut(cur.tree_addr[0] as usize);
|
||||
let mut item_edit = item.write().unwrap();
|
||||
|
||||
|
@ -234,6 +239,17 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
}
|
||||
TreeNavResult::Continue => TreeNavResult::Continue
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
self.cursor.set(
|
||||
ListCursor {
|
||||
mode: ListCursorMode::Insert,
|
||||
idx: Some(0)
|
||||
}
|
||||
);
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue