diff options
author | António Fernandes <antoniof@gnome.org> | 2018-01-13 21:43:41 +0000 |
---|---|---|
committer | Ernestas Kulik <ernestask@gnome.org> | 2018-03-24 20:19:22 +0200 |
commit | ec9877abd2cb89aaa7fc84ecd967db2ced387f87 (patch) | |
tree | 0039df656ac8c64f16b34b3fb1fa0501f3011f1b | |
parent | 6f58b98ee34cdf4876d2c1836b8f25b008a6d08d (diff) | |
download | nautilus-ec9877abd2cb89aaa7fc84ecd967db2ced387f87.tar.gz |
view-icon-controller: Scroll only as necessary to reveal
Currently we always scroll the item to reveal to the top.
This will scroll the item even if it is already visible
but not in the first row.
Instead, scroll as little as necessary to reveal the whole
item, matching the behavior of list view and canvas view.
-rw-r--r-- | src/nautilus-view-icon-controller.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c index f6199ba13..3bcb08517 100644 --- a/src/nautilus-view-icon-controller.c +++ b/src/nautilus-view-icon-controller.c @@ -397,6 +397,7 @@ real_reveal_selection (NautilusFilesView *files_view) GtkAllocation allocation; GtkWidget *content_widget; GtkAdjustment *vadjustment; + int view_height; selection = nautilus_view_get_selection (NAUTILUS_VIEW (files_view)); if (selection == NULL) @@ -409,8 +410,21 @@ real_reveal_selection (NautilusFilesView *files_view) item_ui = nautilus_view_item_model_get_item_ui (item_model); gtk_widget_get_allocation (item_ui, &allocation); content_widget = nautilus_files_view_get_content_widget (files_view); + view_height = gtk_widget_get_allocated_height (content_widget); vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (content_widget)); - gtk_adjustment_set_value (vadjustment, allocation.y); + + /* Scroll only as necessary. TODO: Would be nice to have this as part of + * GtkFlowBox. GtkTreeView has something similar. */ + if (allocation.y < gtk_adjustment_get_value (vadjustment)) + { + gtk_adjustment_set_value (vadjustment, allocation.y); + } + else if (allocation.y + allocation.height > + gtk_adjustment_get_value (vadjustment) + view_height) + { + gtk_adjustment_set_value (vadjustment, + allocation.y + allocation.height - view_height); + } g_list_foreach (selection, (GFunc) g_object_unref, NULL); } |