diff options
author | Havoc Pennington <hp@redhat.com> | 2001-01-04 20:01:32 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-01-04 20:01:32 +0000 |
commit | b0a909b8c41011784d7f369150c3e56a6e7f9ee1 (patch) | |
tree | d267a597ed3cf2edef1b21c37bb2fd8a229a7b93 /gtk | |
parent | c7826b5f63930c960cdb53aa4935ee1f8f7f3b18 (diff) | |
download | gdk-pixbuf-b0a909b8c41011784d7f369150c3e56a6e7f9ee1.tar.gz |
if index is equal to the line length, then position iterator before
2001-01-04 Havoc Pennington <hp@redhat.com>
* gtk/gtktextlayout.c (line_display_index_to_iter): if index is
equal to the line length, then position iterator before paragraph
separators. Fixes crash reported by Mikael Hermansson when
pressing left arrow from the start of a line.
* gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
about byte indexes off the end
(iter_set_from_char_offset): add g_error about char offsets
off the end
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtktextiter.c | 28 | ||||
-rw-r--r-- | gtk/gtktextlayout.c | 23 |
2 files changed, 37 insertions, 14 deletions
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c index e2e0f44cf..c085fb326 100644 --- a/gtk/gtktextiter.c +++ b/gtk/gtktextiter.c @@ -92,12 +92,14 @@ iter_set_from_byte_offset (GtkTextRealIter *iter, { iter_set_common (iter, line); - _gtk_text_line_byte_locate (iter->line, - byte_offset, - &iter->segment, - &iter->any_segment, - &iter->segment_byte_offset, - &iter->line_byte_offset); + if (!_gtk_text_line_byte_locate (iter->line, + byte_offset, + &iter->segment, + &iter->any_segment, + &iter->segment_byte_offset, + &iter->line_byte_offset)) + g_error ("Byte index %d is off the end of the line", + byte_offset); } static void @@ -107,12 +109,14 @@ iter_set_from_char_offset (GtkTextRealIter *iter, { iter_set_common (iter, line); - _gtk_text_line_char_locate (iter->line, - char_offset, - &iter->segment, - &iter->any_segment, - &iter->segment_char_offset, - &iter->line_char_offset); + if (!_gtk_text_line_char_locate (iter->line, + char_offset, + &iter->segment, + &iter->any_segment, + &iter->segment_char_offset, + &iter->line_char_offset)) + g_error ("Char offset %d is off the end of the line", + char_offset); } static void diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c index 458142dec..035d4935a 100644 --- a/gtk/gtktextlayout.c +++ b/gtk/gtktextlayout.c @@ -1929,6 +1929,8 @@ line_display_index_to_iter (GtkTextLayout *layout, gint index, gint trailing) { + gint line_len; + if (index >= display->insert_index + layout->preedit_len) index -= layout->preedit_len; else if (index > display->insert_index) @@ -1937,8 +1939,25 @@ line_display_index_to_iter (GtkTextLayout *layout, trailing = 0; } - _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer), - iter, display->line, index); + line_len = _gtk_text_line_byte_count (display->line); + g_assert (index <= line_len); + + if (index < line_len) + _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer), + iter, display->line, index); + else + { + /* Clamp to end of line - really this clamping should have been done + * before here, maybe in Pango, this is a broken band-aid I think + */ + g_assert (index == line_len); + + _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer), + iter, display->line, 0); + gtk_text_iter_forward_to_delimiters (iter); + } + + /* FIXME should this be cursor positions? */ gtk_text_iter_forward_chars (iter, trailing); } |