Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
inferrna opened this issue Jun 11, 2020 · 1 comment
Open

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

inferrna opened this issue Jun 11, 2020 · 1 comment

Comments

@inferrna
Copy link

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

@gyscos
Copy link
Collaborator

gyscos commented Jan 5, 2022

Hi! I think this has been fixed since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants