From 01e91d300b73e178130cf41d5356122bb8146212 Mon Sep 17 00:00:00 2001 From: John Church Date: Thu, 21 Jul 2016 13:41:37 +0100 Subject: tab: restore the cursor and scroll in an idle. Fix bug where the document doesn't always scroll to the restored cursor position. The reason for this is that after the doc is loaded the text view is still working relocating so we wait until the text view gives us some priority to actually scroll. --- pluma/pluma-tab.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pluma/pluma-tab.c b/pluma/pluma-tab.c index 7ceac758..552de2be 100644 --- a/pluma/pluma-tab.c +++ b/pluma/pluma-tab.c @@ -84,6 +84,8 @@ struct _PlumaTabPrivate gint auto_save : 1; gint ask_if_externally_modified : 1; + + guint idle_scroll; }; #if GTK_CHECK_VERSION (3, 0, 0) @@ -241,6 +243,12 @@ pluma_tab_finalize (GObject *object) if (tab->priv->auto_save_timeout > 0) remove_auto_save_timeout (tab); + if (tab->priv->idle_scroll != 0) + { + g_source_remove (tab->priv->idle_scroll); + tab->priv->idle_scroll = 0; + } + G_OBJECT_CLASS (pluma_tab_parent_class)->finalize (object); } @@ -572,6 +580,14 @@ load_cancelled (GtkWidget *area, g_object_unref (tab); } +static gboolean +scroll_to_cursor (PlumaTab *tab) +{ + pluma_view_scroll_to_cursor (PLUMA_VIEW (tab->priv->view)); + tab->priv->idle_scroll = 0; + return FALSE; +} + static void unrecoverable_reverting_error_message_area_response (GtkWidget *message_area, gint response_id, @@ -1000,8 +1016,14 @@ document_loaded (PlumaDocument *document, gtk_widget_show (emsg); } - /* Scroll to the cursor when the document is loaded */ - pluma_view_scroll_to_cursor (PLUMA_VIEW (tab->priv->view)); + /* Scroll to the cursor when the document is loaded, we need to do it in + * an idle as after the document is loaded the textview is still + * redrawing and relocating its internals. + */ + if (tab->priv->idle_scroll == 0) + { + tab->priv->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab); + } all_documents = pluma_app_get_documents (pluma_app_get_default ()); -- cgit v1.2.1