summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Church <[email protected]>2016-07-21 13:41:37 +0100
committerraveit65 <[email protected]>2016-08-01 21:52:07 +0200
commit01e91d300b73e178130cf41d5356122bb8146212 (patch)
tree67d9f2c7fff6e0489bafb54a152ce49771abdaaf
parent6bc0736d75b206bb3857bf52f38720a5a85515d6 (diff)
downloadpluma-01e91d300b73e178130cf41d5356122bb8146212.tar.bz2
pluma-01e91d300b73e178130cf41d5356122bb8146212.tar.xz
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.
-rw-r--r--pluma/pluma-tab.c26
1 files 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 ());