[gtksourceview] completion: tab in snippet takes precidence over completion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] completion: tab in snippet takes precidence over completion
- Date: Fri, 2 Sep 2022 21:48:29 +0000 (UTC)
commit e8ac375aa5e378627edf3c82790bc5a56f35bf19
Author: Christian Hergert <chergert redhat com>
Date: Fri Sep 2 14:12:24 2022 -0700
completion: tab in snippet takes precidence over completion
If you have an active snippet (especially from a previous copmletion), then
tabbing should move you through the snippet positions, not activate the
completion you might be typing through. You can always still use enter to
activate any completion in the current position.
gtksourceview/gtksourcecompletionlistbox.c | 30 +++++++++++++++++++++++++++++-
gtksourceview/gtksourceview-private.h | 1 +
gtksourceview/gtksourceview.c | 10 ++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourcecompletionlistbox.c b/gtksourceview/gtksourcecompletionlistbox.c
index 47db89c3..4c002b0d 100644
--- a/gtksourceview/gtksourcecompletionlistbox.c
+++ b/gtksourceview/gtksourcecompletionlistbox.c
@@ -27,6 +27,7 @@
#include "gtksourcecompletionlistboxrow-private.h"
#include "gtksourcecompletionproposal.h"
#include "gtksourcecompletionprovider.h"
+#include "gtksourceview-private.h"
struct _GtkSourceCompletionListBox
{
@@ -482,6 +483,33 @@ activate_nth_cb (GtkWidget *widget,
return TRUE;
}
+static gboolean
+activate_nth_tab_cb (GtkWidget *widget,
+ GVariant *param,
+ gpointer user_data)
+{
+ GtkSourceCompletionListBox *self = (GtkSourceCompletionListBox *)widget;
+ GtkSourceView *view;
+
+ g_assert (GTK_SOURCE_IS_COMPLETION_LIST_BOX (self));
+
+ if (self->context == NULL)
+ {
+ return FALSE;
+ }
+
+ /* If Tab was pressed by we have a snippet active, that takes precidence
+ * and we should ignore this completion request.
+ */
+ view = gtk_source_completion_context_get_view (self->context);
+ if (!view || _gtk_source_view_has_snippet (view))
+ {
+ return FALSE;
+ }
+
+ return activate_nth_cb (widget, param, user_data);
+}
+
static gboolean
_gtk_source_completion_list_box_key_pressed_cb (GtkSourceCompletionListBox *self,
guint keyval,
@@ -756,7 +784,7 @@ gtk_source_completion_list_box_class_init (GtkSourceCompletionListBoxClass *klas
gtk_widget_class_add_binding (widget_class, GDK_KEY_9, GDK_ALT_MASK, activate_nth_cb, "(i)", 9);
gtk_widget_class_add_binding (widget_class, GDK_KEY_Return, 0, activate_nth_cb, "(i)", 0);
gtk_widget_class_add_binding (widget_class, GDK_KEY_KP_Enter, 0, activate_nth_cb, "(i)", 0);
- gtk_widget_class_add_binding (widget_class, GDK_KEY_Tab, 0, activate_nth_cb, "(i)", 0);
+ gtk_widget_class_add_binding (widget_class, GDK_KEY_Tab, 0, activate_nth_tab_cb, "(i)", 0);
gtk_widget_class_add_binding (widget_class, GDK_KEY_Right, 0, move_next_alternate, NULL);
gtk_widget_class_add_binding (widget_class, GDK_KEY_Left, 0, move_previous_alternate, NULL);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "assistant.hide", NULL);
diff --git a/gtksourceview/gtksourceview-private.h b/gtksourceview/gtksourceview-private.h
index 46460a6d..72d0ba14 100644
--- a/gtksourceview/gtksourceview-private.h
+++ b/gtksourceview/gtksourceview-private.h
@@ -49,6 +49,7 @@ typedef struct _GtkSourceViewSnippets
gulong buffer_cursor_moved_handler;
} GtkSourceViewSnippets;
+gboolean _gtk_source_view_has_snippet (GtkSourceView *view);
void _gtk_source_view_add_assistant (GtkSourceView *view,
GtkSourceAssistant *assistant);
void _gtk_source_view_remove_assistant (GtkSourceView *view,
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index d0dc90b0..592235e6 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -5541,3 +5541,13 @@ _gtk_source_view_get_current_line_number_bold (GtkSourceView *view)
return priv->current_line_number_bold;
}
+
+gboolean
+_gtk_source_view_has_snippet (GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+
+ return priv->snippets.queue.length > 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]