[gtk/stack-fixes] single selection: Fix a corner-case



commit fc17667b9ff4324c4494e4c0b0ce582e24abe4da
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 9 20:24:30 2019 -0500

    single selection: Fix a corner-case
    
    When the last item is removed in an autoselect
    selection, we end up with a  bad selected-changed
    emission.

 gtk/gtksingleselection.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c
index e830b8af57..eb9f6bb667 100644
--- a/gtk/gtksingleselection.c
+++ b/gtk/gtksingleselection.c
@@ -210,12 +210,18 @@ gtk_single_selection_items_changed_cb (GListModel         *model,
             {
               self->selected = position + (self->selected - position) * added / removed;
               self->selected_item = g_list_model_get_item (self->model, self->selected);
-              if (self->selected_item == NULL && position > 0)
+              if (self->selected_item == NULL)
                 {
-                  self->selected = position - 1;
-                  self->selected_item = g_list_model_get_item (self->model, self->selected);
-                  g_assert (self->selected_item);
+                  if (position > 0)
+                    {
+                      self->selected = position - 1;
+                      self->selected_item = g_list_model_get_item (self->model, self->selected);
+                      g_assert (self->selected_item);
+                    }
+                  else
+                    self->selected = GTK_INVALID_LIST_POSITION;
                 }
+                
               emit_selection_changed = TRUE;
             }
           else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]