Commit b0a909b8 authored by Havoc Pennington's avatar Havoc Pennington Committed by Havoc Pennington

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
parent c7826b5f
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
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
2001-01-03 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
......
......@@ -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
......
......@@ -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);
}
......
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