[gnome-builder/wip/chergert/layout] editor: add helper to scroll to a given line



commit cf0161eaae6f33dfa3a635c6ac0919612985ec60
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 30 17:31:08 2017 -0700

    editor: add helper to scroll to a given line

 libide/editor/ide-editor-perspective.c |    5 ++++-
 libide/editor/ide-editor-view.c        |   22 ++++++++++++++++++++++
 libide/editor/ide-editor-view.h        |    2 ++
 3 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index c1f8a49..1fabdf5 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -182,6 +182,7 @@ ide_editor_perspective_focus_location_full (IdeEditorPerspective *self,
     IdeEditorView *view;
   } lookup = { 0 };
   GtkWidget *stack;
+  guint line;
 
   g_return_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self));
   g_return_if_fail (location != NULL);
@@ -228,9 +229,11 @@ ide_editor_perspective_focus_location_full (IdeEditorPerspective *self,
       return;
     }
 
+  line = ide_source_location_get_line (location);
+
   stack = gtk_widget_get_ancestor (GTK_WIDGET (lookup.view), IDE_TYPE_LAYOUT_STACK);
   ide_layout_stack_set_visible_child (IDE_LAYOUT_STACK (stack), IDE_LAYOUT_VIEW (lookup.view));
-  //ide_layout_view_navigate_to (IDE_LAYOUT_VIEW (lookup.view), location);
+  ide_editor_view_scroll_to_line (lookup.view, line);
   gtk_widget_grab_focus (GTK_WIDGET (lookup.view));
 }
 
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index 05cb81b..c564e00 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -529,3 +529,25 @@ ide_editor_view_get_language_id (IdeEditorView *self)
 
   return NULL;
 }
+
+/**
+ * ide_editor_view_scroll_to_line:
+ * @self: a #IdeEditorView
+ *
+ * This is a helper to quickly jump to a given line without all the
+ * frills.
+ */
+void
+ide_editor_view_scroll_to_line (IdeEditorView *self,
+                                guint          line)
+{
+  GtkTextIter iter;
+
+  g_return_if_fail (IDE_IS_EDITOR_VIEW (self));
+  g_return_if_fail (self->buffer != NULL);
+  g_return_if_fail (line <= G_MAXINT);
+
+  gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (self->buffer), &iter, line);
+  gtk_text_buffer_select_range (GTK_TEXT_BUFFER (self->buffer), &iter, &iter);
+  ide_source_view_scroll_to_iter (self->source_view, &iter, 0.0, TRUE, 1.0, 0.5, FALSE);
+}
diff --git a/libide/editor/ide-editor-view.h b/libide/editor/ide-editor-view.h
index e64c031..f3392d7 100644
--- a/libide/editor/ide-editor-view.h
+++ b/libide/editor/ide-editor-view.h
@@ -33,5 +33,7 @@ G_DECLARE_FINAL_TYPE (IdeEditorView, ide_editor_view, IDE, EDITOR_VIEW, IdeLayou
 IdeBuffer     *ide_editor_view_get_buffer      (IdeEditorView *self);
 IdeSourceView *ide_editor_view_get_view        (IdeEditorView *self);
 const gchar   *ide_editor_view_get_language_id (IdeEditorView *self);
+void           ide_editor_view_scroll_to_line  (IdeEditorView *self,
+                                                guint          line);
 
 G_END_DECLS


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