From 8e16491f959697210eb3612749372ce264217c8b Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Fri, 11 Jul 2014 14:10:00 +0200 Subject: [PATCH] Fix restore scroll when not visible --- gitg/history/gitg-history.vala | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala index 2e2b2abc..0c0df622 100644 --- a/gitg/history/gitg-history.vala +++ b/gitg/history/gitg-history.vala @@ -240,11 +240,12 @@ namespace GitgHistory d_selected.clear(); - Gtk.TreePath startp, endp; - view.get_visible_range(out startp, out endp); - d_scroll_to = null; + Gtk.TreePath startp, endp; + + var isvis = view.get_visible_range(out startp, out endp); + view.get_selection().selected_foreach((model, path, iter) => { var c = d_commit_list_model.commit_from_iter(iter); @@ -253,25 +254,33 @@ namespace GitgHistory d_selected.add(c.get_id()); if (d_scroll_to == null && - startp.compare(path) <= 0 && endp.compare(path) >= 0) + (!isvis || startp.compare(path) <= 0 && endp.compare(path) >= 0)) { - Gdk.Rectangle rect; - Gdk.Rectangle visrect; + if (isvis) + { + Gdk.Rectangle rect; + Gdk.Rectangle visrect; - view.get_cell_area(path, null, out rect); - view.get_visible_rect(out visrect); + view.get_cell_area(path, null, out rect); + view.get_visible_rect(out visrect); - int x, y; + int x, y; - view.convert_tree_to_bin_window_coords(visrect.x, - visrect.y, - out x, - out y); + view.convert_tree_to_bin_window_coords(visrect.x, + visrect.y, + out x, + out y); + + // + 2 seems to work correctly here, but this is probably + // something related to a border or padding of the + // treeview (i.e. theme related) + d_scroll_y = (float)(rect.y + rect.height / 2.0 - y + 2) / (float)visrect.height; + } + else + { + d_scroll_y = 0.5f; + } - // + 2 seems to work correctly here, but this is probably - // something related to a border or padding of the - // treeview (i.e. theme related) - d_scroll_y = (float)(rect.y + rect.height / 2.0 - y + 2) / (float)visrect.height; d_scroll_to = c.get_id(); } }