fix listview row update loses selection (GTK)

Tue, 29 Jul 2025 21:15:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 29 Jul 2025 21:15:49 +0200
changeset 683
ba226c243f3f
parent 682
326e7a5122fa
child 684
3c9b430fb160

fix listview row update loses selection (GTK)

ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/list.c	Tue Jul 29 21:12:04 2025 +0200
+++ b/ui/gtk/list.c	Tue Jul 29 21:15:49 2025 +0200
@@ -626,14 +626,20 @@
         void *value = list->get(list, i);
         if(value) {
             ObjWrapper *obj = obj_wrapper_new(value, i);
+            UiListSelection sel = list->getselection(list);
             // TODO: if index i is selected, the selection is lost
             // is it possible to update the item without removing it?
+            // workaround: save selection and reapply it
             int count = g_list_model_get_n_items(G_LIST_MODEL(view->liststore));
             if(count <= i) {
                 g_list_store_splice(view->liststore, i, 0, (void **)&obj, 1);
             } else {
                 g_list_store_splice(view->liststore, i, 1, (void **)&obj, 1);
             }
+            if(sel.count > 0) {
+                list->setselection(list, sel);
+            }
+            ui_listselection_free(sel);
         }
     }
 }

mercurial