[gtksourceview] Bracket matching: improve cursor_moved()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Bracket matching: improve cursor_moved()
- Date: Sat, 24 Oct 2015 13:49:52 +0000 (UTC)
commit 36b49dad8f53f2dd9a669163b361a50a11f27491
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Oct 24 15:24:42 2015 +0200
Bracket matching: improve cursor_moved()
- Delete the tag if bracket highlighting has been disabled, so that the
next time the function is called, it's faster.
- Make the code clearer, avoid some indentation levels, etc.
gtksourceview/gtksourcebuffer.c | 63 +++++++++++++++++++++++----------------
1 files changed, 37 insertions(+), 26 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 5ca9e06..5924cb4 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -882,18 +882,19 @@ cursor_moved (GtkSourceBuffer *source_buffer)
{
GtkTextBuffer *buffer;
GtkTextIter insert_iter;
- GtkTextIter start;
- GtkTextIter end;
GtkTextIter bracket;
GtkTextIter bracket_match;
GtkSourceBracketMatchType previous_state;
buffer = GTK_TEXT_BUFFER (source_buffer);
- if (source_buffer->priv->bracket_match == GTK_SOURCE_BRACKET_MATCH_FOUND &&
- source_buffer->priv->bracket_match_tag != NULL)
+ if (source_buffer->priv->bracket_match_tag != NULL)
{
+ GtkTextIter start;
+ GtkTextIter end;
+
gtk_text_buffer_get_bounds (buffer, &start, &end);
+
gtk_text_buffer_remove_tag (buffer,
source_buffer->priv->bracket_match_tag,
&start,
@@ -902,6 +903,15 @@ cursor_moved (GtkSourceBuffer *source_buffer)
if (!source_buffer->priv->highlight_brackets)
{
+ if (source_buffer->priv->bracket_match_tag != NULL)
+ {
+ GtkTextTagTable *table;
+
+ table = gtk_text_buffer_get_tag_table (buffer);
+ gtk_text_tag_table_remove (table, source_buffer->priv->bracket_match_tag);
+ source_buffer->priv->bracket_match_tag = NULL;
+ }
+
return;
}
@@ -915,23 +925,10 @@ cursor_moved (GtkSourceBuffer *source_buffer)
&bracket,
&bracket_match);
- if (source_buffer->priv->bracket_match != GTK_SOURCE_BRACKET_MATCH_FOUND)
- {
- /* Don't emit the signal at all if chars at previous and current
- * positions are nonbrackets.
- */
- if (previous_state != GTK_SOURCE_BRACKET_MATCH_NONE ||
- source_buffer->priv->bracket_match != GTK_SOURCE_BRACKET_MATCH_NONE)
- {
- g_signal_emit (source_buffer,
- buffer_signals[BRACKET_MATCHED],
- 0,
- NULL,
- source_buffer->priv->bracket_match);
- }
- }
- else
+ if (source_buffer->priv->bracket_match == GTK_SOURCE_BRACKET_MATCH_FOUND)
{
+ GtkTextIter next_iter;
+
g_signal_emit (source_buffer,
buffer_signals[BRACKET_MATCHED],
0,
@@ -944,21 +941,35 @@ cursor_moved (GtkSourceBuffer *source_buffer)
*/
source_buffer->priv->allow_bracket_match = TRUE;
- end = bracket_match;
- gtk_text_iter_forward_char (&end);
+ next_iter = bracket_match;
+ gtk_text_iter_forward_char (&next_iter);
gtk_text_buffer_apply_tag (buffer,
get_bracket_match_tag (source_buffer),
&bracket_match,
- &end);
+ &next_iter);
- end = bracket;
- gtk_text_iter_forward_char (&end);
+ next_iter = bracket;
+ gtk_text_iter_forward_char (&next_iter);
gtk_text_buffer_apply_tag (buffer,
get_bracket_match_tag (source_buffer),
&bracket,
- &end);
+ &next_iter);
source_buffer->priv->allow_bracket_match = FALSE;
+ return;
+ }
+
+ /* Don't emit the signal at all if chars at previous and current
+ * positions are nonbrackets.
+ */
+ if (previous_state != GTK_SOURCE_BRACKET_MATCH_NONE ||
+ source_buffer->priv->bracket_match != GTK_SOURCE_BRACKET_MATCH_NONE)
+ {
+ g_signal_emit (source_buffer,
+ buffer_signals[BRACKET_MATCHED],
+ 0,
+ NULL,
+ source_buffer->priv->bracket_match);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]