[gnome-builder/wip/gtk4-port] libide/editor: add helper to scroll to visual position



commit 30e5ad04df92f3d967cd9724cb30b1e05686d1ff
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 1 21:13:21 2022 -0700

    libide/editor: add helper to scroll to visual position

 src/libide/editor/ide-editor-page.c | 15 ++++++++++++
 src/libide/editor/ide-editor-page.h | 46 ++++++++++++++++++++-----------------
 2 files changed, 40 insertions(+), 21 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 4e05ab46d..04b88c248 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -789,3 +789,18 @@ ide_editor_page_set_gutter (IdeEditorPage *self,
 
   IDE_EXIT;
 }
+
+void
+ide_editor_page_scroll_to_visual_position (IdeEditorPage *self,
+                                           guint          line,
+                                           guint          column)
+{
+  GtkTextIter iter;
+
+  g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+
+  ide_source_view_get_iter_at_visual_position (self->view, &iter, line, column);
+  gtk_text_buffer_select_range (GTK_TEXT_BUFFER (self->buffer), &iter, &iter);
+  gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (self->view),
+                                      gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (self->buffer)));
+}
diff --git a/src/libide/editor/ide-editor-page.h b/src/libide/editor/ide-editor-page.h
index d49786292..b4ebf0c3d 100644
--- a/src/libide/editor/ide-editor-page.h
+++ b/src/libide/editor/ide-editor-page.h
@@ -37,35 +37,39 @@ IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeEditorPage, ide_editor_page, IDE, EDITOR_PAGE, IdePage)
 
 IDE_AVAILABLE_IN_ALL
-GtkWidget     *ide_editor_page_new                    (IdeBuffer            *buffer);
+GtkWidget     *ide_editor_page_new                       (IdeBuffer            *buffer);
 IDE_AVAILABLE_IN_ALL
-IdeBuffer     *ide_editor_page_get_buffer             (IdeEditorPage        *self);
+IdeBuffer     *ide_editor_page_get_buffer                (IdeEditorPage        *self);
 IDE_AVAILABLE_IN_ALL
-IdeSourceView *ide_editor_page_get_view               (IdeEditorPage        *self);
+IdeSourceView *ide_editor_page_get_view                  (IdeEditorPage        *self);
 IDE_AVAILABLE_IN_ALL
-GFile         *ide_editor_page_get_file               (IdeEditorPage        *self);
+GFile         *ide_editor_page_get_file                  (IdeEditorPage        *self);
 IDE_AVAILABLE_IN_ALL
-IdeGutter     *ide_editor_page_get_gutter             (IdeEditorPage        *self);
+IdeGutter     *ide_editor_page_get_gutter                (IdeEditorPage        *self);
 IDE_AVAILABLE_IN_ALL
-void           ide_editor_page_set_gutter             (IdeEditorPage        *self,
-                                                       IdeGutter            *gutter);
+void           ide_editor_page_set_gutter                (IdeEditorPage        *self,
+                                                          IdeGutter            *gutter);
 IDE_AVAILABLE_IN_ALL
-void           ide_editor_page_discard_changes_async  (IdeEditorPage        *self,
-                                                       GCancellable         *cancellable,
-                                                       GAsyncReadyCallback   callback,
-                                                       gpointer              user_data);
+void           ide_editor_page_discard_changes_async     (IdeEditorPage        *self,
+                                                          GCancellable         *cancellable,
+                                                          GAsyncReadyCallback   callback,
+                                                          gpointer              user_data);
 IDE_AVAILABLE_IN_ALL
-gboolean       ide_editor_page_discard_changes_finish (IdeEditorPage        *self,
-                                                       GAsyncResult         *result,
-                                                       GError              **error);
+gboolean       ide_editor_page_discard_changes_finish    (IdeEditorPage        *self,
+                                                          GAsyncResult         *result,
+                                                          GError              **error);
 IDE_AVAILABLE_IN_ALL
-void           ide_editor_page_save_async             (IdeEditorPage        *self,
-                                                       GCancellable         *cancellable,
-                                                       GAsyncReadyCallback   callback,
-                                                       gpointer              user_data);
+void           ide_editor_page_save_async                (IdeEditorPage        *self,
+                                                          GCancellable         *cancellable,
+                                                          GAsyncReadyCallback   callback,
+                                                          gpointer              user_data);
 IDE_AVAILABLE_IN_ALL
-gboolean       ide_editor_page_save_finish            (IdeEditorPage        *self,
-                                                       GAsyncResult         *result,
-                                                       GError              **error);
+gboolean       ide_editor_page_save_finish               (IdeEditorPage        *self,
+                                                          GAsyncResult         *result,
+                                                          GError              **error);
+IDE_AVAILABLE_IN_ALL
+void           ide_editor_page_scroll_to_visual_position (IdeEditorPage        *self,
+                                                          guint                 line,
+                                                          guint                 column);
 
 G_END_DECLS


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