[gtk+] textiter: fix bug in FindLogAttrFunc functions



commit 69d20f53e237806a64d2ffbe0a859b696667a76f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 15 17:07:14 2014 +0200

    textiter: fix bug in FindLogAttrFunc functions
    
    attrs[len] is the last PangoLogAttr available, at the iter position after the
    last character of the line.
    
    For a line in the middle or the start of the buffer, the '\n' is taken
    into account by 'len'. For example the is_word_end is generally reached
    before the '\n', not after. But for the last line in the buffer, where
    there is no trailing '\n', it is important to test until attrs[len].
    
    The bug didn't occur before because find_by_log_attrs() worked directly
    on the iter passed as the function argument. But now it is no longer the
    case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618852

 gtk/gtktextiter.c        |    6 +++---
 testsuite/gtk/textiter.c |    6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c
index bfc296e..889103e 100644
--- a/gtk/gtktextiter.c
+++ b/gtk/gtktextiter.c
@@ -2895,7 +2895,7 @@ find_word_end_func (const PangoLogAttr *attrs,
     ++offset;
 
   /* Find end of next word */
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_word_end)
         {
@@ -2982,7 +2982,7 @@ find_sentence_end_func (const PangoLogAttr *attrs,
     ++offset;
 
   /* Find end of next sentence */
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_sentence_end)
         {
@@ -3580,7 +3580,7 @@ find_forward_cursor_pos_func (const PangoLogAttr *attrs,
   if (!already_moved_initially)
     ++offset;
 
-  while (offset < len)
+  while (offset <= len)
     {
       if (attrs[offset].is_cursor_position)
         {
diff --git a/testsuite/gtk/textiter.c b/testsuite/gtk/textiter.c
index 09e3bb0..f3b0963 100644
--- a/testsuite/gtk/textiter.c
+++ b/testsuite/gtk/textiter.c
@@ -396,7 +396,7 @@ test_word_boundaries (void)
   check_forward_word_end ("ab ", 1, 2, TRUE);
   check_forward_word_end ("ab ", 2, 2, FALSE);
   check_forward_word_end ("ab ", 3, 3, FALSE);
-  check_forward_word_end ("ab", 0, 0, FALSE); /* FIXME result_offset should be 2 */
+  check_forward_word_end ("ab", 0, 2, FALSE);
 
   check_backward_word_start (" ab", 3, 1, TRUE);
   check_backward_word_start (" ab", 2, 1, 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, 3, FALSE); /* FIXME result_offset should be 4 */
+  check_cursor_position ("a\r\nb", TRUE, 3, 4, FALSE);
   check_cursor_position ("a\r\nb", TRUE, 4, 4, FALSE);
 
   /* backward */
@@ -662,7 +662,7 @@ test_sentence_boundaries (void)
   check_forward_sentence_end ("Hi. ", 2, 3, TRUE);
   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_forward_sentence_end ("Hi.", 0, 3, FALSE);
 
   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]