[gnome-builder] snippets: avoid over activation of snippet completion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: avoid over activation of snippet completion
- Date: Thu, 3 Nov 2016 04:14:19 +0000 (UTC)
commit 4c281a1488eabe0c942272527e7fe3cec59f488e
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 2 21:10:26 2016 -0700
snippets: avoid over activation of snippet completion
We want to be extra careful about when we activate. This prevents us from
activating while in a string/comment which can be fairly annoying.
.../ide-source-snippet-completion-provider.c | 34 ++++++++++++++++++--
1 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/libide/snippets/ide-source-snippet-completion-provider.c
b/libide/snippets/ide-source-snippet-completion-provider.c
index 11c9b70..2da7900 100644
--- a/libide/snippets/ide-source-snippet-completion-provider.c
+++ b/libide/snippets/ide-source-snippet-completion-provider.c
@@ -19,8 +19,9 @@
#include <glib/gi18n.h>
#include <gtksourceview/gtksource.h>
-#include "ide-source-snippet-completion-item.h"
-#include "ide-source-snippet-completion-provider.h"
+#include "snippets/ide-source-snippet-completion-item.h"
+#include "snippets/ide-source-snippet-completion-provider.h"
+#include "sourceview/ide-completion-provider.h"
struct _IdeSourceSnippetCompletionProvider
{
@@ -93,10 +94,37 @@ ide_source_snippet_completion_provider_match (GtkSourceCompletionProvider *provi
GtkSourceCompletionContext *context)
{
IdeSourceSnippetCompletionProvider *self = (IdeSourceSnippetCompletionProvider *)provider;
+ GtkSourceCompletionActivation activation;
+ GtkTextIter iter;
g_assert (IDE_IS_SOURCE_SNIPPET_COMPLETION_PROVIDER (self));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+
+ if (!self->enabled)
+ return FALSE;
+
+ if (ide_completion_provider_context_in_comment_or_string (context))
+ return FALSE;
+
+ if (!gtk_source_completion_context_get_iter (context, &iter))
+ return FALSE;
+
+ activation = gtk_source_completion_context_get_activation (context);
+
+ if (activation == GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE)
+ {
+ gunichar ch;
+
+ if (!gtk_text_iter_starts_line (&iter))
+ gtk_text_iter_backward_char (&iter);
+
+ ch = gtk_text_iter_get_char (&iter);
+
+ if (!g_unichar_isalnum (ch))
+ return FALSE;
+ }
- return self->enabled;
+ return TRUE;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]