[nautilus/wip/antoniof/reverse-file-add-order] files-view: Add files in right order




commit 7700c17bb373c284603c0c4289b95428dc0bba2d
Author: António Fernandes <antoniof gnome org>
Date:   Fri Sep 2 17:15:28 2022 +0100

    files-view: Add files in right order
    
    When populating a GList in a loop, we should use prepend() for best
    performance, then flip it around once with reverse().
    
    The list of pending additions to files view lacks the second part.
    This used to be compensated for by the old views:
    
      * NautilusCanvasView, through NautilusCanvasContainer, would iterate
        this list to populate its own list with prepend(), effectively
        reversing the order, as was necessary.
      * NautilusListView, through NautilusListModel, would iterate this
        list to populate its own list with insert_sorted(), once again
        fixing the loading order.
    
    The new view don't do that, and have no reason to because they don't
    have their own GLists (instead, they manage GListModels). But this
    means that the item which should be added last actually is added first.
    GtkListBase treats the first added item as the initial focus and as
    scroll anchor. The end result is that the view always scrolls to the
    bottom and, on keyboard focus, the last item is selected first.
    
    The first issue (view always scrolls to the bottom) has been worked
    around with a hack, but the second one persists.
    
    Therefore, lets just reverse the list right after it is built. This
    way, the first added item is the one actual first item. It gets initial
    keyboard focus and anchors the view to the top (allowing to remove the
    workaround).
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2353

 src/nautilus-files-view.c |  1 +
 src/nautilus-list-base.c  | 10 ----------
 2 files changed, 1 insertion(+), 10 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index f0d38b4ea..f19fab712 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -4342,6 +4342,7 @@ process_old_files (NautilusFilesView *view)
                                      GUINT_TO_POINTER (TRUE));
             }
         }
+        pending_additions = g_list_reverse (pending_additions);
 
         if (files_added != NULL)
         {
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 52f9f6560..af063e99b 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -1487,20 +1487,10 @@ real_add_files (NautilusFilesView *files_view,
     NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
     g_autoptr (GQueue) files_queue = NULL;
     g_autoptr (GQueue) items = NULL;
-    gdouble adjustment_value;
 
     files_queue = convert_glist_to_queue (files);
     items = convert_files_to_items (self, files_queue);
     nautilus_view_model_add_items (priv->model, items);
-
-    /* GtkListBase anchoring doesn't cope well with our lazy loading.
-     * Assuming that GtkListBase|list.scroll-to-item resets the anchor to 0, use
-     * that as a workaround to prevent scrolling while we are at the top. */
-    adjustment_value = gtk_adjustment_get_value (priv->vadjustment);
-    if (G_APPROX_VALUE (adjustment_value, 0.0, DBL_EPSILON))
-    {
-        nautilus_list_base_scroll_to_item (self, 0);
-    }
 }
 
 static void


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