[gnome-builder] snippets: fix snippet insertion when tabbed in.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: fix snippet insertion when tabbed in.
- Date: Mon, 8 Sep 2014 02:32:09 +0000 (UTC)
commit ed6afb164fcf869d3c64d902d555306ce8656b45
Author: Christian Hergert <christian hergert me>
Date: Sun Sep 7 19:32:03 2014 -0700
snippets: fix snippet insertion when tabbed in.
This ensures that the line prefix will match the line where the snippet
was inserted for each subsequent line.
src/editor/gb-source-view.c | 49 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index e8da095..f16fe8a 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -356,6 +356,44 @@ animate_in (GbSourceView *view,
#undef Y_GROW
}
+static gchar *
+gb_source_view_get_line_prefix (GbSourceView *view,
+ const GtkTextIter *iter)
+{
+ GtkTextIter begin;
+ GString *str;
+
+ g_return_val_if_fail (GB_IS_SOURCE_VIEW (view), NULL);
+ g_return_val_if_fail (iter, NULL);
+
+ gtk_text_iter_assign (&begin, iter);
+ gtk_text_iter_set_line_offset (&begin, 0);
+
+ str = g_string_new (NULL);
+
+ do
+ {
+ gunichar c;
+
+ c = gtk_text_iter_get_char (&begin);
+
+ switch (c)
+ {
+ case '\t':
+ case ' ':
+ g_string_append_unichar (str, c);
+ break;
+ default:
+ g_string_append_c (str, ' ');
+ break;
+ }
+ }
+ while (gtk_text_iter_forward_char (&begin) &&
+ (gtk_text_iter_compare (&begin, iter) < 0));
+
+ return g_string_free (str, FALSE);
+}
+
void
gb_source_view_push_snippet (GbSourceView *view,
GbSourceSnippet *snippet)
@@ -369,6 +407,7 @@ gb_source_view_push_snippet (GbSourceView *view,
gboolean has_more_tab_stops;
gboolean insert_spaces;
gchar *name;
+ gchar *line_prefix;
guint tab_width;
g_return_if_fail (GB_IS_SOURCE_VIEW (view));
@@ -387,15 +426,19 @@ gb_source_view_push_snippet (GbSourceView *view,
g_queue_push_head (priv->snippets, g_object_ref (snippet));
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ mark = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+
insert_spaces = gtk_source_view_get_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (view));
gb_source_snippet_context_set_use_spaces (context, insert_spaces);
tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (view));
gb_source_snippet_context_set_tab_width (context, tab_width);
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- mark = gtk_text_buffer_get_insert (buffer);
- gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+ line_prefix = gb_source_view_get_line_prefix (view, &iter);
+ gb_source_snippet_context_set_line_prefix (context, line_prefix);
+ g_free (line_prefix);
gb_source_view_block_handlers (view);
has_more_tab_stops = gb_source_snippet_begin (snippet, buffer, &iter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]