[gtksourceview/wip/chergert/snippets: 3/3] snippets: (TEST ONLY) expand current word into snippet



commit 08bae0064ccd891e19308e42c92cc0fe67daa81a
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jan 25 08:41:20 2020 -0800

    snippets: (TEST ONLY) expand current word into snippet
    
    This is just for testing the snippet engine with a particularly difficult
    test case (neighboring interactive/linked snippets). It should not be
    merged, but replaced with snippet manager integration.

 gtksourceview/gtksourceview-snippets.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourceview-snippets.c b/gtksourceview/gtksourceview-snippets.c
index 07cd5b97..5004f793 100644
--- a/gtksourceview/gtksourceview-snippets.c
+++ b/gtksourceview/gtksourceview-snippets.c
@@ -308,7 +308,30 @@ lookup_snippet_by_trigger (GtkSourceViewSnippets *snippets,
                            const gchar           *word)
 {
   /* TODO: integrate with snippet manager */
-  return NULL;
+       GtkSourceSnippetChunk *chunk;
+       GtkSourceSnippet *snippet;
+
+       g_assert (snippets != NULL);
+       g_assert (word != NULL);
+
+       snippet = gtk_source_snippet_new (word, NULL);
+
+       for (guint i = 0; i < 3; i++)
+       {
+               chunk = gtk_source_snippet_chunk_new ();
+               if (i == 0)
+                       gtk_source_snippet_chunk_set_spec (chunk, word);
+               else
+                       gtk_source_snippet_chunk_set_spec (chunk, "$1");
+               gtk_source_snippet_chunk_set_focus_position (chunk, i+1);
+               gtk_source_snippet_add_chunk (snippet, chunk);
+       }
+
+       chunk = gtk_source_snippet_chunk_new ();
+       gtk_source_snippet_chunk_set_focus_position (chunk, 0);
+       gtk_source_snippet_add_chunk (snippet, chunk);
+
+       return snippet;
 }
 
 static gboolean


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