if we move to the front of a segment, use the "slow" technique for moving

2001-10-24  Havoc Pennington  <hp@pobox.com>

	* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
	the front of a segment, use the "slow" technique for moving
	backward, so we don't mess up the any_segment field in the iter.
	Fixes #57707

	* tests/testtextbuffer.c: add code to detect #57707, to avoid
	regression
This commit is contained in:
Havoc Pennington 2001-10-24 04:48:21 +00:00 committed by Havoc Pennington
parent fa4e7a31fd
commit da4a311279
10 changed files with 144 additions and 25 deletions

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -1,3 +1,13 @@
2001-10-24 Havoc Pennington <hp@pobox.com>
* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707
* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression
2001-10-23 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (popup_targets_received): only sensitize Cut

View File

@ -96,9 +96,9 @@ Creates a new #GtkMenu.
Adds a new #GtkMenuItem to the end of the menu's item list.
</para>
<!-- # Unused Parameters # -->
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
<!-- # Unused Parameters # -->
@m:
@c:
@ -108,9 +108,9 @@ Adds a new #GtkMenuItem to the end of the menu's item list.
Adds a new #GtkMenuItem to the beginning of the menu's item list.
</para>
<!-- # Unused Parameters # -->
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
<!-- # Unused Parameters # -->
@menu_child:
@m:
@c:
@ -122,10 +122,10 @@ Adds a new #GtkMenuItem to the menu's item list at the position
indicated by @position.
</para>
<!-- # Unused Parameters # -->
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
@pos:
<!-- # Unused Parameters # -->
@position: The position in the item list where @child is added.
Positions are numbered from 0 to n-1.

View File

@ -2347,7 +2347,11 @@ gtk_text_iter_backward_chars (GtkTextIter *iter, gint count)
ensure_char_offsets (real);
check_invariants (iter);
if (count <= real->segment_char_offset)
/* <, not <=, because if count == segment_char_offset
* we're going to the front of the segment and the any_segment
* might change
*/
if (count < real->segment_char_offset)
{
/* Optimize the within-segment case */
g_assert (real->segment->char_count > 0);
@ -2402,6 +2406,7 @@ gtk_text_iter_backward_chars (GtkTextIter *iter, gint count)
new_char_index = current_char_index - count;
if (new_char_index < 0)
new_char_index = 0;
gtk_text_iter_set_offset (iter, new_char_index);
check_invariants (iter);

View File

@ -92,10 +92,10 @@ main (int argc, char** argv)
/* Put stuff in the buffer */
fill_buffer (buffer);
#if 0
/* Subject stuff-bloated buffer to further torment */
run_tests (buffer);
#endif
/* Delete all stuff from the buffer */
gtk_text_buffer_get_bounds (buffer, &start, &end);
gtk_text_buffer_delete (buffer, &start, &end);
@ -112,6 +112,13 @@ main (int argc, char** argv)
run_tests (buffer);
gtk_text_buffer_set_text (buffer, "adcdef", -1);
gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
gtk_text_buffer_apply_tag_by_name (buffer, "fg_blue", &start, &end);
run_tests (buffer);
g_object_unref (G_OBJECT (buffer));
g_print ("All tests passed.\n");
@ -203,32 +210,48 @@ count_toggles_at_iter (GtkTextIter *iter,
return count;
}
static gint
count_toggles_in_buffer (GtkTextBuffer *buffer,
GtkTextTag *of_tag)
count_toggles_in_range_by_char (GtkTextBuffer *buffer,
GtkTextTag *of_tag,
const GtkTextIter *start,
const GtkTextIter *end)
{
GtkTextIter iter;
gint count = 0;
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
iter = *start;
do
{
count += count_toggles_at_iter (&iter, of_tag);
if (!gtk_text_iter_forward_char (&iter))
{
/* end iterator */
count += count_toggles_at_iter (&iter, of_tag);
break;
}
}
while (gtk_text_iter_forward_char (&iter));
/* Do the end iterator, because forward_char won't return TRUE
* on it.
*/
count += count_toggles_at_iter (&iter, of_tag);
while (gtk_text_iter_compare (&iter, end) <= 0);
return count;
}
static gint
count_toggles_in_buffer (GtkTextBuffer *buffer,
GtkTextTag *of_tag)
{
GtkTextIter start, end;
gtk_text_buffer_get_bounds (buffer, &start, &end);
return count_toggles_in_range_by_char (buffer, of_tag, &start, &end);
}
static void
check_specific_tag (GtkTextBuffer *buffer,
const gchar *tag_name)
check_specific_tag_in_range (GtkTextBuffer *buffer,
const gchar *tag_name,
const GtkTextIter *start,
const GtkTextIter *end)
{
GtkTextIter iter;
GtkTextTag *tag;
@ -236,17 +259,23 @@ check_specific_tag (GtkTextBuffer *buffer,
gint count;
gint buffer_count;
gint last_offset;
if (gtk_text_iter_compare (start, end) > 0)
{
g_print (" (inverted range for checking tags, skipping)\n");
return;
}
tag = gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table (buffer),
tag_name);
buffer_count = count_toggles_in_buffer (buffer, tag);
buffer_count = count_toggles_in_range_by_char (buffer, tag, start, end);
state = FALSE;
count = 0;
last_offset = -1;
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
iter = *start;
if (gtk_text_iter_toggles_tag (&iter, tag) ||
gtk_text_iter_forward_to_tag_toggle (&iter, tag))
{
@ -278,17 +307,18 @@ check_specific_tag (GtkTextBuffer *buffer,
else
g_error ("forward_to_tag_toggle went to a location without a toggle");
}
while (gtk_text_iter_forward_to_tag_toggle (&iter, tag));
while (gtk_text_iter_forward_to_tag_toggle (&iter, tag) &&
gtk_text_iter_compare (&iter, end) <= 0);
}
if (count != buffer_count)
g_error ("Counted %d tags iterating by char, %d iterating by tag toggle\n",
g_error ("Counted %d tags iterating by char, %d iterating forward by tag toggle\n",
buffer_count, count);
state = FALSE;
count = 0;
gtk_text_buffer_get_end_iter (buffer, &iter);
iter = *end;
last_offset = gtk_text_iter_get_offset (&iter);
if (gtk_text_iter_toggles_tag (&iter, tag) ||
gtk_text_iter_backward_to_tag_toggle (&iter, tag))
@ -321,13 +351,27 @@ check_specific_tag (GtkTextBuffer *buffer,
else
g_error ("backward_to_tag_toggle went to a location without a toggle");
}
while (gtk_text_iter_backward_to_tag_toggle (&iter, tag));
while (gtk_text_iter_backward_to_tag_toggle (&iter, tag) &&
gtk_text_iter_compare (&iter, start) >= 0);
}
if (count != buffer_count)
g_error ("Counted %d tags iterating by char, %d iterating by tag toggle\n",
g_error ("Counted %d tags iterating by char, %d iterating backward by tag toggle\n",
buffer_count, count);
}
static void
check_specific_tag (GtkTextBuffer *buffer,
const gchar *tag_name)
{
GtkTextIter start, end;
gtk_text_buffer_get_bounds (buffer, &start, &end);
check_specific_tag_in_range (buffer, tag_name, &start, &end);
gtk_text_iter_forward_chars (&start, 2);
gtk_text_iter_backward_chars (&end, 2);
if (gtk_text_iter_compare (&start, &end) < 0)
check_specific_tag_in_range (buffer, tag_name, &start, &end);
}
static void