[gnome-builder] editor: add helper to scroll to line and offset



commit 9aaf2d1fca23b349131f37fb2b26a927119c1790
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 23 14:20:06 2017 -0700

    editor: add helper to scroll to line and offset

 libide/editor/ide-editor-view.c |   29 ++++++++++++++++++++++++++++-
 libide/editor/ide-editor-view.h |    3 +++
 2 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index fe54a79..5a04af7 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -856,16 +856,42 @@ ide_editor_view_get_language_id (IdeEditorView *self)
 /**
  * ide_editor_view_scroll_to_line:
  * @self: a #IdeEditorView
+ * @line: the line to scroll to
  *
  * This is a helper to quickly jump to a given line without all the frills. It
  * will also ensure focus on the editor view, so that refocusing the view
  * afterwards does not cause the view to restore the cursor to the previous
  * location.
+ *
+ * This will move the insert cursor.
+ *
+ * Lines start from 0.
  */
 void
 ide_editor_view_scroll_to_line (IdeEditorView *self,
                                 guint          line)
 {
+  ide_editor_view_scroll_to_line_offset (self, line, 0);
+}
+
+/**
+ * ide_editor_view_scroll_to_line_offset:
+ * @self: a #IdeEditorView
+ * @line: the line to scroll to
+ * @line_offset: the line offset
+ *
+ * Like ide_editor_view_scroll_to_line() but allows specifying the
+ * line offset (column) to place the cursor on.
+ *
+ * This will move the insert cursor.
+ *
+ * Lines and offsets start from 0.
+ */
+void
+ide_editor_view_scroll_to_line_offset (IdeEditorView *self,
+                                       guint          line,
+                                       guint          line_offset)
+{
   GtkTextIter iter;
 
   g_return_if_fail (IDE_IS_EDITOR_VIEW (self));
@@ -874,7 +900,8 @@ ide_editor_view_scroll_to_line (IdeEditorView *self,
 
   gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
 
-  gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (self->buffer), &iter, line);
+  gtk_text_buffer_get_iter_at_line_offset (GTK_TEXT_BUFFER (self->buffer), &iter,
+                                           line, line_offset);
   gtk_text_buffer_select_range (GTK_TEXT_BUFFER (self->buffer), &iter, &iter);
   ide_source_view_scroll_to_insert (self->source_view);
 }
diff --git a/libide/editor/ide-editor-view.h b/libide/editor/ide-editor-view.h
index 1a36b49..bf28cd7 100644
--- a/libide/editor/ide-editor-view.h
+++ b/libide/editor/ide-editor-view.h
@@ -35,6 +35,9 @@ IdeSourceView     *ide_editor_view_get_view                    (IdeEditorView
 const gchar       *ide_editor_view_get_language_id             (IdeEditorView     *self);
 void               ide_editor_view_scroll_to_line              (IdeEditorView     *self,
                                                                 guint              line);
+void               ide_editor_view_scroll_to_line_offset       (IdeEditorView     *self,
+                                                                guint              line,
+                                                                guint              line_offset);
 gboolean           ide_editor_view_get_auto_hide_map           (IdeEditorView     *self);
 void               ide_editor_view_set_auto_hide_map           (IdeEditorView     *self,
                                                                 gboolean           auto_hide_map);


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