[gtksourceview/wip/chergert/snippets] make snippet expansion work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/snippets] make snippet expansion work
- Date: Wed, 29 Jan 2020 01:06:25 +0000 (UTC)
commit a42fd49c153b5e81f904a8dd0c7eb8c99b8d760d
Author: Christian Hergert <chergert redhat com>
Date: Tue Jan 28 17:06:07 2020 -0800
make snippet expansion work
gtksourceview/gtksourcesnippetbundle-parser.c | 5 +---
gtksourceview/gtksourcesnippetbundle.c | 2 +-
gtksourceview/gtksourceview-snippets.c | 35 +++++++++++++--------------
3 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/gtksourceview/gtksourcesnippetbundle-parser.c b/gtksourceview/gtksourcesnippetbundle-parser.c
index 317f45e9..86e79ada 100644
--- a/gtksourceview/gtksourcesnippetbundle-parser.c
+++ b/gtksourceview/gtksourcesnippetbundle-parser.c
@@ -224,10 +224,7 @@ do_part (TextParser *parser,
gchar *name;
glong n;
- g_assert (line);
- g_assert (*line == '\t');
-
- line++;
+ g_assert (line != NULL);
again:
if (!*line)
diff --git a/gtksourceview/gtksourcesnippetbundle.c b/gtksourceview/gtksourcesnippetbundle.c
index 0bd5d55b..9ba5abcd 100644
--- a/gtksourceview/gtksourcesnippetbundle.c
+++ b/gtksourceview/gtksourcesnippetbundle.c
@@ -127,7 +127,6 @@ text_and_cdata (GMarkupParseContext *context,
g_assert (state != NULL);
g_assert (GTK_SOURCE_IS_SNIPPET_BUNDLE (state->self));
- g_string_truncate (state->text, 0);
g_string_append_len (state->text, text, text_len);
}
@@ -213,6 +212,7 @@ elements_end_element (GMarkupParseContext *context,
}
g_clear_pointer (&state->languages, g_strfreev);
+ g_string_truncate (state->text, 0);
g_markup_parse_context_pop (context);
}
diff --git a/gtksourceview/gtksourceview-snippets.c b/gtksourceview/gtksourceview-snippets.c
index 5004f793..1ef930ee 100644
--- a/gtksourceview/gtksourceview-snippets.c
+++ b/gtksourceview/gtksourceview-snippets.c
@@ -23,8 +23,10 @@
#include "gtksourcebuffer.h"
#include "gtksourceiter-private.h"
+#include "gtksourcelanguage.h"
#include "gtksourcesnippet-private.h"
#include "gtksourcesnippetchunk.h"
+#include "gtksourcesnippetmanager.h"
#include "gtksourceview-private.h"
static void
@@ -307,31 +309,27 @@ static GtkSourceSnippet *
lookup_snippet_by_trigger (GtkSourceViewSnippets *snippets,
const gchar *word)
{
- /* TODO: integrate with snippet manager */
- GtkSourceSnippetChunk *chunk;
- GtkSourceSnippet *snippet;
+ GtkSourceSnippetManager *manager;
+ GtkSourceLanguage *language;
+ const gchar *language_id = NULL;
g_assert (snippets != NULL);
g_assert (word != NULL);
- snippet = gtk_source_snippet_new (word, NULL);
-
- for (guint i = 0; i < 3; i++)
+ if (word[0] == 0)
{
- 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);
+ return NULL;
}
- chunk = gtk_source_snippet_chunk_new ();
- gtk_source_snippet_chunk_set_focus_position (chunk, 0);
- gtk_source_snippet_add_chunk (snippet, chunk);
+ manager = gtk_source_snippet_manager_get_default ();
+ language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (snippets->buffer));
+
+ if (language != NULL)
+ {
+ language_id = gtk_source_language_get_id (language);
+ }
- return snippet;
+ return gtk_source_snippet_manager_get_snippet (manager, NULL, language_id, word);
}
static gboolean
@@ -373,7 +371,8 @@ gtk_source_view_snippets_try_expand (GtkSourceViewSnippets *snippets,
if (snippet != NULL)
{
- _gtk_source_view_snippets_push (snippets, snippet, iter);
+ gtk_text_buffer_delete (snippets->buffer, &begin, iter);
+ gtk_source_view_push_snippet (snippets->view, snippet, iter);
g_object_unref (snippet);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]