[gnome-builder/gnome-builder-3-30] history: push cursor location upon buffer load



commit e7d3e5da5e5e49a40bab1e20a7c8af26a03e93b9
Author: Christian Hergert <chergert redhat com>
Date:   Mon Sep 17 11:51:34 2018 -0700

    history: push cursor location upon buffer load

 .../history/gbp-history-editor-view-addin.c        | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/src/plugins/history/gbp-history-editor-view-addin.c 
b/src/plugins/history/gbp-history-editor-view-addin.c
index aa8195bed..655d7b80c 100644
--- a/src/plugins/history/gbp-history-editor-view-addin.c
+++ b/src/plugins/history/gbp-history-editor-view-addin.c
@@ -205,6 +205,32 @@ gbp_history_editor_view_addin_delete_range (GbpHistoryEditorViewAddin *self,
     gbp_history_editor_view_addin_queue (self, gtk_text_iter_get_line (begin));
 }
 
+static void
+gbp_history_editor_view_addin_buffer_loaded (GbpHistoryEditorViewAddin *self,
+                                             IdeBuffer                 *buffer)
+{
+  IdeSourceView *source_view;
+
+  g_assert (GBP_IS_HISTORY_EDITOR_VIEW_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_VIEW (self->editor));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  /*
+   * The cursor should have settled here, push it's location onto the
+   * history stack so that ctrl+i works after jumping backwards.
+   */
+
+  source_view = ide_editor_view_get_view (self->editor);
+
+  if (gtk_widget_has_focus (GTK_WIDGET (source_view)))
+    {
+      GtkTextIter iter;
+
+      ide_buffer_get_selection_bounds (buffer, &iter, NULL);
+      gbp_history_editor_view_addin_queue (self, gtk_text_iter_get_line (&iter));
+    }
+}
+
 static void
 gbp_history_editor_view_addin_load (IdeEditorViewAddin *addin,
                                     IdeEditorView      *view)
@@ -237,6 +263,11 @@ gbp_history_editor_view_addin_load (IdeEditorViewAddin *addin,
                             "delete-range",
                             G_CALLBACK (gbp_history_editor_view_addin_delete_range),
                             self);
+
+  g_signal_connect_swapped (buffer,
+                            "loaded",
+                            G_CALLBACK (gbp_history_editor_view_addin_buffer_loaded),
+                            self);
 }
 
 static void
@@ -267,6 +298,10 @@ gbp_history_editor_view_addin_unload (IdeEditorViewAddin *addin,
                                         G_CALLBACK (gbp_history_editor_view_addin_delete_range),
                                         self);
 
+  g_signal_handlers_disconnect_by_func (buffer,
+                                        G_CALLBACK (gbp_history_editor_view_addin_buffer_loaded),
+                                        self);
+
   g_clear_weak_pointer (&self->stack_addin);
 
   self->editor = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]