mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 19:00:08 +00:00
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
This commit is contained in:
parent
79c835a151
commit
5d66634482
@ -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;
|
||||
|
||||
return !gtk_text_iter_equal (iter, &orig) && !gtk_text_iter_is_end (iter);
|
||||
gtk_text_iter_set_line_offset (&iter, offset);
|
||||
|
||||
moved = !gtk_text_iter_equal (&iter, arg_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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user