After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 748265 - Scroll jumps back to first selected item
Scroll jumps back to first selected item
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: Views: Icon View
3.16.x
Other Linux
: Normal minor
: 3.16
Assigned To: Nautilus Maintainers
Nautilus Maintainers
: 748522 749985 753143 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-04-21 21:34 UTC by Mantas Mikulėnas (grawity)
Modified: 2017-08-22 22:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
canvas-view: only change action states when they change (2.45 KB, patch)
2015-04-28 20:34 UTC, Georges Basile Stavracas Neto
needs-work Details | Review
canvas-view: change action states only when the value differs (2.69 KB, patch)
2015-04-30 13:02 UTC, Georges Basile Stavracas Neto
none Details | Review
canvas-view: change action states only when the value differs (3.05 KB, patch)
2015-04-30 14:24 UTC, Georges Basile Stavracas Neto
none Details | Review
canvas-view: change action states only when the value differs (3.40 KB, patch)
2015-04-30 15:06 UTC, Georges Basile Stavracas Neto
none Details | Review
canvas-view: change action states only when the value differs (3.40 KB, patch)
2015-04-30 15:07 UTC, Georges Basile Stavracas Neto
committed Details | Review

Description Mantas Mikulėnas (grawity) 2015-04-21 21:34:44 UTC
So in icon view, I select a few files (using Ctrl+click), then scroll down and try to select more, but every time I do that, the view keeps scrolling back to the 'first' (topmost) selection, and I have to scroll down again to select the next file.

nautilus 3.16.0 (& git master)
Comment 1 Nelson Benitez 2015-04-27 15:58:33 UTC
I've investigated this, it's a regression caused by commit bb884cb6 (cc'ing Carlos), when clicking a canvas icon:

update_context_menus_timeout_callback() is called, which calls nautilus_canvas_view_update_actions_state () which calls g_action_group_change_action_state() on the "sort" action, so it's telling nautilus that's been a change in the sort order of the view (which is false, the sort order has not changed! that's the bug) so, the nautilus handler for when the sort order is changed is to scroll and reveal the first selected item, which is right behaviour.

I'm attaching the gdb backtrace in a following comment.
Comment 2 Nelson Benitez 2015-04-27 16:00:34 UTC
(gdb) bt
  • #0 nautilus_canvas_view_reveal_selection
    at nautilus-canvas-view.c line 1126
  • #1 action_sort_order_changed
    at nautilus-canvas-view.c line 950
  • #2 g_cclosure_marshal_VOID__VARIANT
    at gmarshal.c line 2140
  • #3 g_closure_invoke
    at gclosure.c line 801
  • #4 signal_emit_unlocked_R
    at gsignal.c line 3549
  • #5 g_signal_emit_valist
    at gsignal.c line 3305
  • #6 g_signal_emit
    at gsignal.c line 3361
  • #7 g_simple_action_change_state
    at gsimpleaction.c line 140
  • #8 g_action_change_state
    at gaction.c line 208
  • #9 g_simple_action_group_change_state
    at gsimpleactiongroup.c line 122
  • #10 g_action_group_change_action_state
    at gactiongroup.c line 569
  • #11 nautilus_canvas_view_update_actions_state
    at nautilus-canvas-view.c line 1078
  • #12 update_context_menus_timeout_callback
    at nautilus-view.c line 3176
  • #13 g_timeout_dispatch
    at gmain.c line 4545
  • #14 g_main_dispatch
    at gmain.c line 3122
  • #15 g_main_context_dispatch
    at gmain.c line 3737
  • #16 g_main_context_iterate
    at gmain.c line 3808
  • #17 g_main_context_iteration
    at gmain.c line 3869
  • #18 g_application_run
    at gapplication.c line 2308
  • #19 main
    at nautilus-main.c line 103

Comment 3 Nelson Benitez 2015-04-27 16:25:39 UTC
*** Bug 748522 has been marked as a duplicate of this bug. ***
Comment 4 Carlos Soriano 2015-04-27 16:30:13 UTC
thanks for the debugging, the problem is clear. Will take a look.
Comment 5 Georges Basile Stavracas Neto 2015-04-28 20:34:01 UTC
Created attachment 302530 [details] [review]
canvas-view: only change action states when they change

This avoid an undesired change on "sort" state, which
causes an invalidation of the canvas and moves the
scroll to the first selected item.
Comment 6 Carlos Soriano 2015-04-29 09:38:55 UTC
Review of attachment 302530 [details] [review]:

For the commit message:
The title reads odd. Only change it when it changes =)
I would say: change the action state only when the value differs

Also the comment from Nelson explains well one part.
"the nautilus handler for when the sort order is changed is to scroll and reveal the first selected item"
In your commit message is not clear if scrolling to the first item is a bug, part of the bug or is the intended behaviour. That sentence from Nelson makes it clearer.

So I would do something like:

title

Context (nautilus scrolls to the first item when the sort state is changed because bla blah, and there fore we need to call it when the sort changes)
What generates the bug (currently we change the action state everytime when we update menus which triggers the sort changed handler)
What we do to fix it (avoid to change the action state if the new value don't actually differ from the current one)

::: src/nautilus-canvas-view.c
@@ +1068,3 @@
+		reversed_state = g_action_group_get_action_state (view_action_group, "reversed-order");
+
+		if (reversed_state &&

this reads as: If the current action value is NULL, don't change the value.

That is not what you probably want.

Also these actions are stateful (if they wouldn't we won't bother to get the value etc), you don't need to check for NULL. NULL returning here is only as a way to returning something for not stateful actions.

Also, in case the action is no stateful, calling g_action_group_change_action_state in any part of the code for this action will be an error.
Comment 7 Carlos Soriano 2015-04-29 09:40:02 UTC
(In reply to Carlos Soriano from comment #6)
> Review of attachment 302530 [details] [review] [review]:
> 
> For the commit message:
> The title reads odd. Only change it when it changes =)
> I would say: change the action state only when the value differs
> 
> Also the comment from Nelson explains well one part.
> "the nautilus handler for when the sort order is changed is to scroll and
> reveal the first selected item"
> In your commit message is not clear if scrolling to the first item is a bug,
> part of the bug or is the intended behaviour. That sentence from Nelson
> makes it clearer.
> 
> So I would do something like:
> 
> title
> 
> Context (nautilus scrolls to the first item when the sort state is changed
> because bla blah, and there fore we need to call it when the sort changes)
> What generates the bug (currently we change the action state everytime when
> we update menus which triggers the sort changed handler)
> What we do to fix it (avoid to change the action state if the new value
> don't actually differ from the current one)

With an empty line between those three things to make it clear
Comment 8 Georges Basile Stavracas Neto 2015-04-30 13:02:00 UTC
Created attachment 302649 [details] [review]
canvas-view: change action states only when the value differs

Commit bb884cb6 introduced the faulty behavior, with
NautilusCanvasView scrolling back to the first selected
item when selecting multiple items.

Backtracing it, it was found out that the icon view
was invalidating the "sort" state when selecting items,
which is obviously false since the ordering of the items
does not depend on the selection.

The issue is fixed by only changing the "sort" state when
it makes sense, i.e. only when the states really change.
Comment 9 Carlos Soriano 2015-04-30 14:04:01 UTC
Review of attachment 302649 [details] [review]:

I'm still not very happy with the commit message. did you see my comments in the previous one? Like explaining why we were doing that. It would be nice to know the reason we are updating the sort order etc.
What do you think? Maybe it's not too important for this fix if the comment is good in the code, but looks like something good to follow the commit guidelines just in case.

Code looks good.

::: src/nautilus-canvas-view.c
@@ +1067,3 @@
+		sort_state = g_action_group_get_action_state (view_action_group, "sort");
+		reversed_state = g_action_group_get_action_state (view_action_group, "reversed-order");
+

Could you add comment in code for what we need this?
Comment 10 Georges Basile Stavracas Neto 2015-04-30 14:24:09 UTC
Created attachment 302655 [details] [review]
canvas-view: change action states only when the value differs

Commit bb884cb6 introduced the faulty behavior where
NautilusCanvasView scrolling back to the first selected
item when selecting multiple items.

Backtracing it, it was found out that the icon view
was invalidating the "sort" state when selecting items,
which is obviously false since the ordering of the items
does not depend on the selection. Nautilus automatically
scrolls to the first sorted item when that happens.

The issue is fixed by only changing the "sort" state when
it makes sense, i.e. only when the states really change.
Comment 11 Georges Basile Stavracas Neto 2015-04-30 15:06:36 UTC
Created attachment 302661 [details] [review]
canvas-view: change action states only when the value differs

Commit bb884cb6 introduced the faulty behavior where
NautilusCanvasView keeps scrolling back to the first
selected item when selecting multiple items.

Backtracing it, it was found out that the icon view
was changing the "sort" state when selecting items,
even if nothing actually changed, which triggers the
sort action changed handler. The handler by itself
was doing the right job by revealing the selection,
and the issue was caused by calling it unnecessarily.

Since we may have to update the action states for other
reasons besidse real sort change, we must change the
action state only when it makes sense, i.e. only when
the states really change.
Comment 12 Georges Basile Stavracas Neto 2015-04-30 15:07:35 UTC
Created attachment 302662 [details] [review]
canvas-view: change action states only when the value differs

Commit bb884cb6 introduced the faulty behavior where
NautilusCanvasView keeps scrolling back to the first
selected item when selecting multiple items.

Backtracing it, it was found out that the icon view
was changing the "sort" state when selecting items,
even if nothing actually changed, which triggers the
sort action changed handler. The handler by itself
was doing the right job by revealing the selection,
and the issue was caused by calling it unnecessarily.

Since we may have to update the action states for other
reasons besidse real sort change, we must change the
action state only when it makes sense, i.e. only when
the states really change.
Comment 13 Carlos Soriano 2015-04-30 15:30:07 UTC
Review of attachment 302662 [details] [review]:

Good enought, thanks!

::: src/nautilus-canvas-view.c
@@ +1072,3 @@
+		 * To achieve this, check if the action state value actually changed before setting
+		 * it.
+		 * the sort action changed handler, which reveals the selection, since we expect

And the same for the reversed state. =) just add it and commit
Comment 14 Georges Basile Stavracas Neto 2015-04-30 15:37:53 UTC
Attachment 302662 [details] pushed as 0ff112a - canvas-view: change action states only when the value differs
Comment 15 Luc Pi 2015-05-05 07:36:21 UTC
a small workaround in the meantime:
start selection from the bottom, then the view does not jump

(go to bottom, select a few / scroll a page up / select a few / and so on)
Comment 16 Carlos Soriano 2015-05-27 17:21:01 UTC
*** Bug 749985 has been marked as a duplicate of this bug. ***
Comment 17 António Fernandes 2017-08-22 22:58:12 UTC
*** Bug 753143 has been marked as a duplicate of this bug. ***