gridview: Limit rectangle to gridview columns
authorCorey Berla <corey@berla.me>
Thu, 5 May 2022 04:33:26 +0000 (21:33 -0700)
committerCorey Berla <corey@berla.me>
Tue, 26 Jul 2022 00:27:24 +0000 (17:27 -0700)
The function gtk_grid_view_get_items_in_rect() erroneously calculates
columns less than 0 and greater than n_columns when the user attempts
to rubberband all the way to the left or right respectively.  This
causes the rubberband to persistent and creates unexpected behavior.
Limit the rows to a minimum of 0 and maximum of n_columns - 1.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3445
gtk/gtkgridview.c

index 6f2b7b03544f2f80f427e3a1087ad0d94f09c6c0..c2a4abe9d28a521121b600fc97e404a79f760889 100644 (file)
@@ -484,8 +484,8 @@ gtk_grid_view_get_items_in_rect (GtkListBase        *base,
   if (n_items == 0)
     return result;
 
-  first_column = floor (rect->x / self->column_width);
-  last_column = floor ((rect->x + rect->width) / self->column_width);
+  first_column = fmax (floor (rect->x / self->column_width), 0);
+  last_column = fmin (floor ((rect->x + rect->width) / self->column_width), self->n_columns - 1);
   if (!gtk_grid_view_get_cell_at_y (self, rect->y, &first_row, NULL, NULL))
     first_row = rect->y < 0 ? 0 : n_items - 1;
   if (!gtk_grid_view_get_cell_at_y (self, rect->y + rect->height, &last_row, NULL, NULL))