[gnome-builder/editor-layout] editor: plumb support for scrolling to target line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/editor-layout] editor: plumb support for scrolling to target line
- Date: Mon, 1 Dec 2014 07:40:37 +0000 (UTC)
commit 029cfc210422c8d0eeec3710e49fcc838f4506da
Author: Christian Hergert <christian hergert me>
Date: Sun Nov 30 23:40:14 2014 -0800
editor: plumb support for scrolling to target line
src/editor/gb-editor-tab.c | 29 +++++++++++++++++++++++++++++
src/editor/gb-editor-tab.h | 23 +++++++++++++----------
2 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 149a157..8b7c25e 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -338,6 +338,35 @@ gb_editor_tab_get_last_frame (GbEditorTab *tab)
return tab->priv->frame;
}
+void
+gb_editor_tab_scroll_to_line (GbEditorTab *tab,
+ guint line,
+ guint line_offset)
+{
+ GbEditorFrame *frame;
+ GtkTextIter iter;
+
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ frame = gb_editor_tab_get_last_frame (tab);
+
+ gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (tab->priv->document),
+ &iter, line);
+ for (; line_offset; line_offset--)
+ {
+ if (gtk_text_iter_ends_line (&iter))
+ break;
+ if (!gtk_text_iter_forward_char (&iter))
+ break;
+ }
+
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (tab->priv->document),
+ &iter, &iter);
+
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (frame->priv->source_view), &iter,
+ 0.0, FALSE, 0.0, 0.5);
+}
+
static void
gb_editor_tab_scroll (GbEditorTab *tab,
GtkDirectionType dir)
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index 11b9c66..f35627f 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -51,16 +51,19 @@ struct _GbEditorTabClass
GbTabClass parent_class;
};
-GbEditorTab *gb_editor_tab_new (void);
-GType gb_editor_tab_get_type (void) G_GNUC_CONST;
-void gb_editor_tab_save (GbEditorTab *tab);
-void gb_editor_tab_save_as (GbEditorTab *tab);
-void gb_editor_tab_open_file (GbEditorTab *tab,
- GFile *file);
-void gb_editor_tab_scroll_up (GbEditorTab *tab);
-void gb_editor_tab_scroll_down (GbEditorTab *tab);
-void gb_editor_tab_toggle_split (GbEditorTab *tab);
-void gb_editor_tab_find (GbEditorTab *tab);
+GbEditorTab *gb_editor_tab_new (void);
+GType gb_editor_tab_get_type (void) G_GNUC_CONST;
+void gb_editor_tab_save (GbEditorTab *tab);
+void gb_editor_tab_save_as (GbEditorTab *tab);
+void gb_editor_tab_open_file (GbEditorTab *tab,
+ GFile *file);
+void gb_editor_tab_scroll_up (GbEditorTab *tab);
+void gb_editor_tab_scroll_down (GbEditorTab *tab);
+void gb_editor_tab_toggle_split (GbEditorTab *tab);
+void gb_editor_tab_find (GbEditorTab *tab);
+void gb_editor_tab_scroll_to_line (GbEditorTab *tab,
+ guint line,
+ guint line_offset);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]