Skip to content

Error when trying set_items() shorten than actual selection #19

@inferrna

Description

@inferrna

Steps to reproduce

  1. Apply this diff to basic example
diff --git a/examples/basic.rs b/examples/basic.rs
index 677bb81..5969863 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -100,22 +100,20 @@ fn main() {
     });
 
     table.set_on_submit(|siv: &mut Cursive, row: usize, index: usize| {
-        let value = siv
-            .call_on_name("table", move |table: &mut TableView<Foo, BasicColumn>| {
-                format!("{:?}", table.borrow_item(index).unwrap())
+        siv.call_on_name("table", move |table: &mut TableView<Foo, BasicColumn>| {
+                let mut items = Vec::new();
+                let mut rng = rand::thread_rng();
+                for i in 0..49 {
+                    items.push(Foo {
+                        name: format!("Name {}", i),
+                        count: rng.gen_range(0, 255),
+                        rate: rng.gen_range(0, 255),
+                    });
+                }
+
+                table.set_items(items);
             })
             .unwrap();
-
-        siv.add_layer(
-            Dialog::around(TextView::new(value))
-                .title(format!("Removing row # {}", row))
-                .button("Close", move |s| {
-                    s.call_on_name("table", |table: &mut TableView<Foo, BasicColumn>| {
-                        table.remove_item(index);
-                    });
-                    s.pop_layer();
-                }),
-        );
     });
 
     siv.add_layer(Dialog::around(table.with_name("table").min_size((50, 20))).title("Table View"));
  1. Run (redirect output to log file)
  2. Scroll to last item and submit on it

In the log file you will see
thread 'main' panicked at 'index out of bounds: the len is 49 but the index is 49', /tmp/cursive_table_view/src/lib.rs:486:18

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions