[gnome-builder/auto-indent] auto-indent: use parent class for insertion of keyval.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/auto-indent] auto-indent: use parent class for insertion of keyval.
- Date: Thu, 18 Sep 2014 08:58:19 +0000 (UTC)
commit 005275a1d9ebc9c9dd300a685a5d89d734b4c285
Author: Christian Hergert <christian hergert me>
Date: Thu Sep 18 01:58:14 2014 -0700
auto-indent: use parent class for insertion of keyval.
Otherwise, we would insert CR instead of \n. This let's us use the default
binding. We just need to ensure that auto-indent is disabled.
Possibly should override that property in GbSourceView.
src/editor/gb-editor-settings.c | 2 +-
src/editor/gb-source-auto-indenter-c.c | 3 ---
src/editor/gb-source-change-monitor.c | 4 ++++
src/editor/gb-source-view.c | 18 ++++++------------
4 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/src/editor/gb-editor-settings.c b/src/editor/gb-editor-settings.c
index 6043213..7cc2b8e 100644
--- a/src/editor/gb-editor-settings.c
+++ b/src/editor/gb-editor-settings.c
@@ -644,7 +644,7 @@ gb_editor_settings_init (GbEditorSettings *settings)
font_desc = pango_font_description_from_string (DEFAULT_FONT);
- settings->priv->auto_indent = TRUE;
+ settings->priv->auto_indent = FALSE;
settings->priv->show_right_margin = TRUE;
settings->priv->highlight_current_line = TRUE;
settings->priv->show_line_numbers = TRUE;
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index 4a97f9a..bc69096 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -338,8 +338,6 @@ gb_source_auto_indenter_c_indent (GbSourceAutoIndenterC *c,
*/
ch = gtk_text_iter_get_char (iter);
- g_print ("char is now: %c\n", ch);
-
/*
* If we just placed a terminating parenthesis, we need to work our way back
* to it's match. That way we can peak at what it was and determine
@@ -456,7 +454,6 @@ gb_source_auto_indenter_c_format (GbSourceAutoIndenter *indenter,
case GDK_KEY_KP_Enter:
gtk_text_iter_assign (&begin_copy, begin);
ret = gb_source_auto_indenter_c_indent (c, view, buffer, begin);
- g_print ("INDENT: \"%s\"\n", ret);
gtk_text_iter_assign (begin, &begin_copy);
break;
diff --git a/src/editor/gb-source-change-monitor.c b/src/editor/gb-source-change-monitor.c
index 0f56007..861b830 100644
--- a/src/editor/gb-source-change-monitor.c
+++ b/src/editor/gb-source-change-monitor.c
@@ -316,6 +316,8 @@ on_insert_text_after_cb (GbSourceChangeMonitor *monitor,
GbSourceChangeFlags flags = 0;
guint line;
+ ENTRY;
+
g_return_if_fail (GB_IS_SOURCE_CHANGE_MONITOR (monitor));
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
@@ -367,6 +369,8 @@ on_insert_text_after_cb (GbSourceChangeMonitor *monitor,
}
gb_source_change_monitor_ensure_bounds (monitor);
+
+ EXIT;
}
GbSourceChangeFlags
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index d1f2fdc..ec64502 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -757,24 +757,18 @@ gb_source_view_key_press_event (GtkWidget *widget,
GtkTextMark *insert;
GtkTextIter begin;
GtkTextIter end;
- gunichar ch;
- GString *str;
gchar *indent;
if ((event->keyval == GDK_KEY_Return) || (event->keyval == GDK_KEY_KP_Enter))
if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
return TRUE;
- gtk_text_buffer_begin_user_action (priv->buffer);
-
/*
- * Insert the current keypress into the buffer.
+ * Insert into the buffer so the auto-indenter sees it. If
+ * GtkSourceView:auto-indent is set, then we will end up with
+ * very unpredictable results.
*/
- str = g_string_new (NULL);
- ch = gdk_keyval_to_unicode (event->keyval);
- g_string_append_unichar (str, ch);
- gtk_text_buffer_insert_at_cursor (priv->buffer, str->str, str->len);
- g_string_free (str, TRUE);
+ GTK_WIDGET_CLASS (gb_source_view_parent_class)->key_press_event (widget, event);
/*
* Set begin and end to the position of the new insertion point.
@@ -793,14 +787,14 @@ gb_source_view_key_press_event (GtkWidget *widget,
if (indent)
{
+ gtk_text_buffer_begin_user_action (priv->buffer);
if (!gtk_text_iter_equal (&begin, &end))
gtk_text_buffer_delete (priv->buffer, &begin, &end);
gtk_text_buffer_insert (priv->buffer, &begin, indent, -1);
g_free (indent);
+ gtk_text_buffer_end_user_action (priv->buffer);
}
- gtk_text_buffer_end_user_action (priv->buffer);
-
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]