[gnome-builder] snippet-completion: cleanup proposal activation



commit 23836846954977192021c4ee41e02cc02e0aef7b
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 11 02:41:37 2016 -0800

    snippet-completion: cleanup proposal activation

 .../ide-source-snippet-completion-provider.c       |   68 ++++++++++----------
 1 files changed, 35 insertions(+), 33 deletions(-)
---
diff --git a/libide/snippets/ide-source-snippet-completion-provider.c 
b/libide/snippets/ide-source-snippet-completion-provider.c
index 2da7900..7a93468 100644
--- a/libide/snippets/ide-source-snippet-completion-provider.c
+++ b/libide/snippets/ide-source-snippet-completion-provider.c
@@ -386,42 +386,44 @@ provider_activate_proposal (GtkSourceCompletionProvider *provider,
                             GtkSourceCompletionProposal *proposal,
                             GtkTextIter                 *iter)
 {
-  IdeSourceSnippetCompletionItem *item;
-  IdeSourceSnippet *snippet;
-  GtkTextBuffer *buffer;
-  GtkTextIter end;
-  gchar *word;
-  IdeSourceSnippetCompletionProvider *self = IDE_SOURCE_SNIPPET_COMPLETION_PROVIDER (provider);
+  IdeSourceSnippetCompletionProvider *self = (IdeSourceSnippetCompletionProvider *)provider;
+  IdeSourceSnippetCompletionItem *item = (IdeSourceSnippetCompletionItem *)proposal;
+
+  g_assert (IDE_IS_SOURCE_SNIPPET_COMPLETION_PROVIDER (self));
+  g_assert (IDE_IS_SOURCE_SNIPPET_COMPLETION_ITEM (item));
 
   if (self->source_view)
     {
-      item = IDE_SOURCE_SNIPPET_COMPLETION_ITEM (proposal);
-      snippet = ide_source_snippet_completion_item_get_snippet (item);
-      if (snippet)
-        {
-          /*
-           * Fetching the word will move us back to the beginning of it.
-           */
-          gtk_text_iter_assign (&end, iter);
-          word = get_word (provider, iter);
-          g_free (word);
-
-          /*
-           * Now delete the current word since it will get overwritten
-           * by the insertion of the snippet.
-           */
-          buffer = gtk_text_iter_get_buffer (iter);
-          gtk_text_buffer_delete (buffer, iter, &end);
-
-          /*
-           * Now push snippet onto the snippet stack of the view.
-           */
-          snippet = ide_source_snippet_copy (snippet);
-          ide_source_view_push_snippet (IDE_SOURCE_VIEW (self->source_view), snippet, NULL);
-          g_object_unref (snippet);
-
-          return TRUE;
-        }
+      IdeSourceSnippet *snippet;
+      GtkTextBuffer *buffer;
+      GtkTextIter begin;
+      gchar *word;
+
+      if (NULL == (snippet = ide_source_snippet_completion_item_get_snippet (item)))
+        return FALSE;
+
+      /*
+       * Fetching the word will move us back to the beginning of it.
+       */
+      begin = *iter;
+      word = get_word (provider, &begin);
+      g_free (word);
+
+      /*
+       * Now delete the current word since it will get overwritten
+       * by the insertion of the snippet.
+       */
+      buffer = gtk_text_iter_get_buffer (iter);
+      gtk_text_buffer_delete (buffer, &begin, iter);
+
+      /*
+       * Now push snippet onto the snippet stack of the view.
+       */
+      snippet = ide_source_snippet_copy (snippet);
+      ide_source_view_push_snippet (IDE_SOURCE_VIEW (self->source_view), snippet, NULL);
+      g_object_unref (snippet);
+
+      return TRUE;
     }
 
   return FALSE;


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