Skip to content

files-view: Add files in right order

António Fernandes requested to merge wip/antoniof/reverse-file-add-order into master

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: #2353 (closed)

Merge request reports