Commit 0d5635b3 authored by Havoc Pennington's avatar Havoc Pennington Committed by Havoc Pennington

don't back up a char from the end iterator, fixes #61859 ("can't put

2001-10-22  Havoc Pennington  <hp@redhat.com>

	* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
	up a char from the end iterator, fixes #61859 ("can't put cursor
	at the end of the buffer")

	* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
	to work with delimiters other than newline.

	* tests/testtextbuffer.c: add some tests for get_chars_in_line,
	get_bytes_in_line

	* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
	last line, since the newline is no longer counted.
	(gtk_text_iter_get_bytes_in_line): ditto
parent 60ef9dd4
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back
up a char from the end iterator, fixes #61859 ("can't put cursor
at the end of the buffer")
* gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this
to work with delimiters other than newline.
* tests/testtextbuffer.c: add some tests for get_chars_in_line,
get_bytes_in_line
* gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the
last line, since the newline is no longer counted.
(gtk_text_iter_get_bytes_in_line): ditto
2001-10-22 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
......
......@@ -1866,9 +1866,6 @@ gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
real = *where;
if (gtk_text_iter_is_end (&real))
gtk_text_iter_backward_char (&real);
_gtk_text_btree_place_cursor (get_btree (buffer), &real);
gtk_text_buffer_mark_set (buffer, &real,
gtk_text_buffer_get_mark (buffer,
......
......@@ -1658,6 +1658,9 @@ gtk_text_iter_get_chars_in_line (const GtkTextIter *iter)
seg = seg->next;
}
if (_gtk_text_line_contains_end_iter (real->line, real->tree))
count -= 1; /* Dump the newline that was in the last segment of the end iter line */
return count;
}
......@@ -1706,6 +1709,9 @@ gtk_text_iter_get_bytes_in_line (const GtkTextIter *iter)
seg = seg->next;
}
if (_gtk_text_line_contains_end_iter (real->line, real->tree))
count -= 1; /* Dump the newline that was in the last segment of the end iter line */
return count;
}
......@@ -3486,7 +3492,7 @@ gtk_text_iter_set_line_offset (GtkTextIter *iter,
iter_set_from_char_offset (real, real->line, char_on_line);
else
gtk_text_iter_forward_line (iter); /* set to start of next line */
check_invariants (iter);
}
......@@ -3735,6 +3741,30 @@ gtk_text_iter_forward_to_end (GtkTextIter *iter)
gtk_text_buffer_get_end_iter (buffer, iter);
}
/* FIXME this and gtk_text_iter_forward_to_line_end() could be cleaned up
* and made faster. Look at iter_ends_line() for inspiration, perhaps.
* If all else fails we could cache the para delimiter pos in the iter.
* I think forward_to_line_end() actually gets called fairly often.
*/
static int
find_paragraph_delimiter_for_line (GtkTextIter *iter)
{
GtkTextIter end;
end = *iter;
/* if we aren't on the last line, go forward to start of next line, then scan
* back for the delimiters on the previous line
*/
if (gtk_text_iter_forward_line (&end))
{
gtk_text_iter_backward_char (&end);
while (!gtk_text_iter_ends_line (&end))
gtk_text_iter_backward_char (&end);
}
return gtk_text_iter_get_line_offset (&end);
}
/**
* gtk_text_iter_forward_to_line_end:
* @iter: a #GtkTextIter
......@@ -3744,7 +3774,9 @@ gtk_text_iter_forward_to_end (GtkTextIter *iter)
* return/newline in sequence, or the Unicode paragraph separator
* character. If the iterator is already at the paragraph delimiter
* characters, moves to the paragraph delimiter characters for the
* next line.
* next line. If @iter is on the last line in the buffer, which does
* not end in paragraph delimiters, moves to the end iterator (end of
* the last line), and returns %FALSE.
*
* Return value: %TRUE if we moved and the new location is not the end iterator
**/
......@@ -3754,12 +3786,12 @@ gtk_text_iter_forward_to_line_end (GtkTextIter *iter)
gint current_offset;
gint new_offset;
g_return_val_if_fail (iter != NULL, FALSE);
current_offset = gtk_text_iter_get_line_offset (iter);
/* FIXME assumption that line ends in a newline; broken */
new_offset = gtk_text_iter_get_chars_in_line (iter) - 1;
new_offset = find_paragraph_delimiter_for_line (iter);
if (current_offset < new_offset)
{
/* Move to end of this line. */
......
......@@ -67,6 +67,15 @@ main (int argc, char** argv)
if (n != 0)
g_error ("%d chars, expected 0", n);
/* empty first line contains 0 chars */
gtk_text_buffer_get_start_iter (buffer, &start);
n = gtk_text_iter_get_chars_in_line (&start);
if (n != 0)
g_error ("%d chars in first line, expected 0", n);
n = gtk_text_iter_get_bytes_in_line (&start);
if (n != 0)
g_error ("%d bytes in first line, expected 0", n);
/* Run gruesome alien test suite on buffer */
run_tests (buffer);
......@@ -77,6 +86,8 @@ main (int argc, char** argv)
check_get_set_text (buffer, "Hello\r");
check_get_set_text (buffer, "Hello\nBar\nFoo");
check_get_set_text (buffer, "Hello\nBar\nFoo\n");
g_print ("get/set tests passed.\n");
/* Put stuff in the buffer */
......@@ -112,7 +123,7 @@ static void
check_get_set_text (GtkTextBuffer *buffer,
const char *str)
{
GtkTextIter start, end;
GtkTextIter start, end, iter;
char *text;
int n;
......@@ -127,6 +138,32 @@ check_get_set_text (GtkTextBuffer *buffer,
g_error ("Got '%s' as buffer contents", text);
g_free (text);
/* line char counts */
iter = start;
n = 0;
do
{
n += gtk_text_iter_get_chars_in_line (&iter);
}
while (gtk_text_iter_forward_line (&iter));
if (n != gtk_text_buffer_get_char_count (buffer))
g_error ("Sum of chars in lines is %d but buffer char count is %d",
n, gtk_text_buffer_get_char_count (buffer));
/* line byte counts */
iter = start;
n = 0;
do
{
n += gtk_text_iter_get_bytes_in_line (&iter);
}
while (gtk_text_iter_forward_line (&iter));
if (n != strlen (str))
g_error ("Sum of chars in lines is %d but buffer byte count is %d",
n, strlen (str));
gtk_text_buffer_set_text (buffer, "", -1);
n = gtk_text_buffer_get_line_count (buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment