[gnome-builder] GbSourceView: don't auto insert ")]} if we are in a comment or string.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] GbSourceView: don't auto insert ")]} if we are in a comment or string.
- Date: Sat, 3 Jan 2015 00:32:33 +0000 (UTC)
commit 20d48819f3b2affead0814e19e8ba9c92d3c7a99
Author: Christian Hergert <christian hergert me>
Date: Fri Jan 2 16:31:54 2015 -0800
GbSourceView: don't auto insert ")]} if we are in a comment or string.
src/editor/gb-source-view.c | 45 +++++++++++++++++++++++-------------------
1 files changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index ec39069..3b9849b 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -1432,13 +1432,13 @@ static gboolean
gb_source_view_maybe_insert_match (GbSourceView *view,
GdkEventKey *event)
{
- GtkTextIter iter;
- GtkTextIter next_iter;
- GtkTextIter prev_iter;
+ GtkSourceBuffer *sbuf;
GtkTextBuffer *buffer;
GtkTextMark *insert;
+ GtkTextIter iter;
+ GtkTextIter prev_iter;
+ GtkTextIter next_iter;
gunichar next_ch = 0;
- gunichar prev_ch = 0;
gchar ch = 0;
/*
@@ -1450,9 +1450,30 @@ gb_source_view_maybe_insert_match (GbSourceView *view,
g_return_val_if_fail (GB_IS_SOURCE_VIEW (view), FALSE);
g_return_val_if_fail (event, FALSE);
+ /*
+ * If we are disabled, then do nothing.
+ */
if (!view->priv->insert_matching_brace)
return FALSE;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ sbuf = GTK_SOURCE_BUFFER (buffer);
+
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+ next_ch = gtk_text_iter_get_char (&iter);
+
+ prev_iter = iter;
+ gtk_text_iter_backward_chars (&prev_iter, 2);
+
+ /*
+ * If the source language has marked this region as a string or comment,
+ * then do nothing.
+ */
+ if (gtk_source_buffer_iter_has_context_class (sbuf, &prev_iter, "string") ||
+ gtk_source_buffer_iter_has_context_class (sbuf, &prev_iter, "comment"))
+ return FALSE;
+
switch (event->keyval)
{
case GDK_KEY_braceleft:
@@ -1486,22 +1507,6 @@ gb_source_view_maybe_insert_match (GbSourceView *view,
return FALSE;
}
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- insert = gtk_text_buffer_get_insert (buffer);
- gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
- next_ch = gtk_text_iter_get_char (&iter);
-
- prev_iter = iter;
- gtk_text_iter_backward_chars (&prev_iter, 2);
- prev_ch = gtk_text_iter_get_char (&prev_iter);
-
- /*
- * If we are inserting right after \ (pretty much universal escape character,
- * so probably not worth abstracting), then just do nothing.
- */
- if (prev_ch == '\\')
- return FALSE;
-
/*
* Insert the match if one of the following is true:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]