summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Church <[email protected]>2016-07-21 13:41:37 +0100
committermonsta <[email protected]>2016-08-12 22:14:04 +0300
commitfdcc8abd1b21e9c3cdbd7ce4433482ea4b7d44e6 (patch)
tree9b8bc4db75ce48491f3a6b61627a392ab2d7bb07
parent0a50b2121cf6227ecd1fc6a821932de4694f5978 (diff)
downloadpluma-fdcc8abd1b21e9c3cdbd7ce4433482ea4b7d44e6.tar.bz2
pluma-fdcc8abd1b21e9c3cdbd7ce4433482ea4b7d44e6.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 723dfaf1..e735696d 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 ());