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
This commit is contained in:

committed by
Havoc Pennington

parent
60ef9dd421
commit
0d5635b366
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
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>
|
2001-10-22 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
* gtk/gtktextbtree.c (_gtk_text_btree_insert): add assertion that
|
||||||
|
@ -1866,9 +1866,6 @@ gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
|
|||||||
|
|
||||||
real = *where;
|
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_btree_place_cursor (get_btree (buffer), &real);
|
||||||
gtk_text_buffer_mark_set (buffer, &real,
|
gtk_text_buffer_mark_set (buffer, &real,
|
||||||
gtk_text_buffer_get_mark (buffer,
|
gtk_text_buffer_get_mark (buffer,
|
||||||
|
@ -1658,6 +1658,9 @@ gtk_text_iter_get_chars_in_line (const GtkTextIter *iter)
|
|||||||
seg = seg->next;
|
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;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1706,6 +1709,9 @@ gtk_text_iter_get_bytes_in_line (const GtkTextIter *iter)
|
|||||||
seg = seg->next;
|
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;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3735,6 +3741,30 @@ gtk_text_iter_forward_to_end (GtkTextIter *iter)
|
|||||||
gtk_text_buffer_get_end_iter (buffer, 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:
|
* gtk_text_iter_forward_to_line_end:
|
||||||
* @iter: a #GtkTextIter
|
* @iter: a #GtkTextIter
|
||||||
@ -3744,7 +3774,9 @@ gtk_text_iter_forward_to_end (GtkTextIter *iter)
|
|||||||
* return/newline in sequence, or the Unicode paragraph separator
|
* return/newline in sequence, or the Unicode paragraph separator
|
||||||
* character. If the iterator is already at the paragraph delimiter
|
* character. If the iterator is already at the paragraph delimiter
|
||||||
* characters, moves to the paragraph delimiter characters for the
|
* 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
|
* Return value: %TRUE if we moved and the new location is not the end iterator
|
||||||
**/
|
**/
|
||||||
@ -3754,11 +3786,11 @@ gtk_text_iter_forward_to_line_end (GtkTextIter *iter)
|
|||||||
gint current_offset;
|
gint current_offset;
|
||||||
gint new_offset;
|
gint new_offset;
|
||||||
|
|
||||||
|
|
||||||
g_return_val_if_fail (iter != NULL, FALSE);
|
g_return_val_if_fail (iter != NULL, FALSE);
|
||||||
|
|
||||||
current_offset = gtk_text_iter_get_line_offset (iter);
|
current_offset = gtk_text_iter_get_line_offset (iter);
|
||||||
/* FIXME assumption that line ends in a newline; broken */
|
new_offset = find_paragraph_delimiter_for_line (iter);
|
||||||
new_offset = gtk_text_iter_get_chars_in_line (iter) - 1;
|
|
||||||
|
|
||||||
if (current_offset < new_offset)
|
if (current_offset < new_offset)
|
||||||
{
|
{
|
||||||
|
@ -67,6 +67,15 @@ main (int argc, char** argv)
|
|||||||
if (n != 0)
|
if (n != 0)
|
||||||
g_error ("%d chars, expected 0", n);
|
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 gruesome alien test suite on buffer */
|
||||||
run_tests (buffer);
|
run_tests (buffer);
|
||||||
|
|
||||||
@ -78,6 +87,8 @@ main (int argc, char** argv)
|
|||||||
check_get_set_text (buffer, "Hello\nBar\nFoo");
|
check_get_set_text (buffer, "Hello\nBar\nFoo");
|
||||||
check_get_set_text (buffer, "Hello\nBar\nFoo\n");
|
check_get_set_text (buffer, "Hello\nBar\nFoo\n");
|
||||||
|
|
||||||
|
g_print ("get/set tests passed.\n");
|
||||||
|
|
||||||
/* Put stuff in the buffer */
|
/* Put stuff in the buffer */
|
||||||
|
|
||||||
fill_buffer (buffer);
|
fill_buffer (buffer);
|
||||||
@ -112,7 +123,7 @@ static void
|
|||||||
check_get_set_text (GtkTextBuffer *buffer,
|
check_get_set_text (GtkTextBuffer *buffer,
|
||||||
const char *str)
|
const char *str)
|
||||||
{
|
{
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end, iter;
|
||||||
char *text;
|
char *text;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@ -127,6 +138,32 @@ check_get_set_text (GtkTextBuffer *buffer,
|
|||||||
g_error ("Got '%s' as buffer contents", text);
|
g_error ("Got '%s' as buffer contents", text);
|
||||||
g_free (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);
|
gtk_text_buffer_set_text (buffer, "", -1);
|
||||||
|
|
||||||
n = gtk_text_buffer_get_line_count (buffer);
|
n = gtk_text_buffer_get_line_count (buffer);
|
||||||
|
Reference in New Issue
Block a user