[gtk+] textiter: fix bug in find_by_log_attrs()



commit 5d666344820bc23330f128109c011848ec744736
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jul 13 22:20:25 2014 +0200

    textiter: fix bug in find_by_log_attrs()
    
    Do not work with the iter passed as the function argument. Work with
    another iter, and set it back to the function argument only if something
    has been found.
    
    This fixes a few unit tests. But there are regressions for a few others.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618852

 gtk/gtktextiter.c        |   33 +++++++++++++++++----------------
 testsuite/gtk/textiter.c |   11 ++++++-----
 2 files changed, 23 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c
index f445240..8d9a140 100644
--- a/gtk/gtktextiter.c
+++ b/gtk/gtktextiter.c
@@ -3097,54 +3097,55 @@ find_line_log_attrs (const GtkTextIter *iter,
 }
 
 static gboolean
-find_by_log_attrs (GtkTextIter     *iter,
+find_by_log_attrs (GtkTextIter     *arg_iter,
                    FindLogAttrFunc  func,
                    gboolean         forward)
 {
-  GtkTextIter orig;
+  GtkTextIter iter;
   gboolean already_moved_initially = FALSE;
 
-  g_return_val_if_fail (iter != NULL, FALSE);
+  g_return_val_if_fail (arg_iter != NULL, FALSE);
 
-  orig = *iter;
+  iter = *arg_iter;
 
   while (TRUE)
     {
       gint offset = 0;
       gboolean found;
 
-      found = find_line_log_attrs (iter, func, &offset, already_moved_initially);
+      found = find_line_log_attrs (&iter, func, &offset, already_moved_initially);
 
       if (found)
         {
-          gtk_text_iter_set_line_offset (iter, offset);
+          gboolean moved;
+
+          gtk_text_iter_set_line_offset (&iter, offset);
+
+          moved = !gtk_text_iter_equal (&iter, arg_iter);
 
-          return !gtk_text_iter_equal (iter, &orig) && !gtk_text_iter_is_end (iter);
+          *arg_iter = iter;
+          return moved && !gtk_text_iter_is_end (arg_iter);
         }
 
       if (forward)
         {
-          if (!gtk_text_iter_forward_line (iter))
+          if (!gtk_text_iter_forward_line (&iter))
             return FALSE;
 
           already_moved_initially = TRUE;
         }
       else
         {
-          GtkTextIter tmp_iter = *iter;
-
           /* Go to end of previous line. First go to the current line offset 0,
            * because backward_line() snaps to start of line 0 if iter is already
            * on line 0.
            */
-          gtk_text_iter_set_line_offset (&tmp_iter, 0);
+          gtk_text_iter_set_line_offset (&iter, 0);
 
-          if (gtk_text_iter_backward_line (&tmp_iter))
+          if (gtk_text_iter_backward_line (&iter))
             {
-              *iter = tmp_iter;
-
-              if (!gtk_text_iter_ends_line (iter))
-                gtk_text_iter_forward_to_line_end (iter);
+              if (!gtk_text_iter_ends_line (&iter))
+                gtk_text_iter_forward_to_line_end (&iter);
 
               already_moved_initially = TRUE;
             }
diff --git a/testsuite/gtk/textiter.c b/testsuite/gtk/textiter.c
index 04fb5da..09e3bb0 100644
--- a/testsuite/gtk/textiter.c
+++ b/testsuite/gtk/textiter.c
@@ -394,13 +394,13 @@ test_word_boundaries (void)
 
   check_forward_word_end ("ab ", 0, 2, TRUE);
   check_forward_word_end ("ab ", 1, 2, TRUE);
-  check_forward_word_end ("ab ", 2, 3, FALSE); /* FIXME bug? */
+  check_forward_word_end ("ab ", 2, 2, FALSE);
   check_forward_word_end ("ab ", 3, 3, FALSE);
-  check_forward_word_end ("ab", 0, 2, FALSE); /* the FALSE is strange here */
+  check_forward_word_end ("ab", 0, 0, FALSE); /* FIXME result_offset should be 2 */
 
   check_backward_word_start (" ab", 3, 1, TRUE);
   check_backward_word_start (" ab", 2, 1, TRUE);
-  check_backward_word_start (" ab", 1, 1, FALSE); /* FIXME Inconsistent with the equivalent for 
forward_word_end() */
+  check_backward_word_start (" ab", 1, 1, FALSE);
   check_backward_word_start (" ab", 0, 0, FALSE);
   check_backward_word_start ("ab", 2, 0, TRUE);
 }
@@ -520,7 +520,7 @@ test_cursor_positions (void)
   check_cursor_position ("a\r\nb", TRUE, 0, 1, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 1, 3, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 2, 3, TRUE);
-  check_cursor_position ("a\r\nb", TRUE, 3, 4, FALSE);
+  check_cursor_position ("a\r\nb", TRUE, 3, 3, FALSE); /* FIXME result_offset should be 4 */
   check_cursor_position ("a\r\nb", TRUE, 4, 4, FALSE);
 
   /* backward */
@@ -660,8 +660,9 @@ test_sentence_boundaries (void)
   check_forward_sentence_end ("Hi. ", 0, 3, TRUE);
   check_forward_sentence_end ("Hi. ", 1, 3, TRUE);
   check_forward_sentence_end ("Hi. ", 2, 3, TRUE);
-  check_forward_sentence_end ("Hi. ", 3, 4, FALSE); /* FIXME result_offset should be 3 */
+  check_forward_sentence_end ("Hi. ", 3, 3, FALSE);
   check_forward_sentence_end ("Hi. ", 4, 4, FALSE);
+  check_forward_sentence_end ("Hi.", 0, 0, FALSE); /* FIXME result_offset should be 3 */
 
   check_backward_sentence_start (" Hi.", 4, 1, TRUE);
   check_backward_sentence_start (" Hi.", 3, 1, TRUE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]