[gtksourceview/wip/improve-bracket-matching] Bracket matching: fix minor bug with return value
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/improve-bracket-matching] Bracket matching: fix minor bug with return value
- Date: Sat, 24 Oct 2015 08:47:03 +0000 (UTC)
commit 5ca4c3fef8e9452fe55e577fe09c22d8fc6b2d1f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Oct 24 10:44:05 2015 +0200
Bracket matching: fix minor bug with return value
gtksourceview/gtksourcebuffer.c | 40 +++++++++++++++++++++++++++++++-------
tests/test-buffer.c | 6 +---
2 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index d6e7ede..78e7626 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -1271,7 +1271,8 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer *buffer,
GtkTextIter *bracket,
GtkTextIter *bracket_match)
{
- GtkSourceBracketMatchType result;
+ GtkSourceBracketMatchType result_right;
+ GtkSourceBracketMatchType result_left;
GtkTextIter prev;
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), GTK_SOURCE_BRACKET_MATCH_NONE);
@@ -1279,9 +1280,9 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer *buffer,
g_return_val_if_fail (bracket_match != NULL, GTK_SOURCE_BRACKET_MATCH_NONE);
*bracket_match = *pos;
- result = gtk_source_buffer_find_bracket_match_real (buffer, bracket_match);
+ result_right = gtk_source_buffer_find_bracket_match_real (buffer, bracket_match);
- if (result == GTK_SOURCE_BRACKET_MATCH_FOUND)
+ if (result_right == GTK_SOURCE_BRACKET_MATCH_FOUND)
{
if (bracket != NULL)
{
@@ -1296,16 +1297,39 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer *buffer,
gtk_text_iter_backward_cursor_position (&prev))
{
*bracket_match = prev;
- result = gtk_source_buffer_find_bracket_match_real (buffer, bracket_match);
+ result_left = gtk_source_buffer_find_bracket_match_real (buffer, bracket_match);
+ }
+ else
+ {
+ result_left = GTK_SOURCE_BRACKET_MATCH_NONE;
}
- if (result == GTK_SOURCE_BRACKET_MATCH_FOUND &&
- bracket != NULL)
+ if (result_left == GTK_SOURCE_BRACKET_MATCH_FOUND)
{
- *bracket = prev;
+ if (bracket != NULL)
+ {
+ *bracket = prev;
+ }
+
+ return GTK_SOURCE_BRACKET_MATCH_FOUND;
}
- return result;
+ /* If there is a bracket, the expected return value is for the bracket,
+ * not the other character.
+ */
+ if (result_right == GTK_SOURCE_BRACKET_MATCH_NONE)
+ {
+ return result_left;
+ }
+ if (result_left == GTK_SOURCE_BRACKET_MATCH_NONE)
+ {
+ return result_right;
+ }
+
+ /* There are brackets on both sides, and none was successful. The one on
+ * the right takes precedence.
+ */
+ return result_right;
}
/**
diff --git a/tests/test-buffer.c b/tests/test-buffer.c
index ea33868..e61eeb5 100644
--- a/tests/test-buffer.c
+++ b/tests/test-buffer.c
@@ -382,13 +382,11 @@ test_bracket_matching (void)
do_test_bracket_matching (buffer, "((\"(ab))\")", 0, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 0, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
- /* FIXME expected NOT_FOUND. */
- do_test_bracket_matching (buffer, "\"(\"a\")\"", 1, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
+ do_test_bracket_matching (buffer, "\"(\"a\")\"", 1, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 2, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 3, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 4, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
- /* FIXME expected NOT_FOUND. */
- do_test_bracket_matching (buffer, "\"(\"a\")\"", 5, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
+ do_test_bracket_matching (buffer, "\"(\"a\")\"", 5, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 6, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
do_test_bracket_matching (buffer, "\"(\"a\")\"", 7, -1, -1, GTK_SOURCE_BRACKET_MATCH_NONE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]