summaryrefslogtreecommitdiff
path: root/gtk/gtktextbtree.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/gtktextbtree.c')
-rw-r--r--gtk/gtktextbtree.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gtk/gtktextbtree.c b/gtk/gtktextbtree.c
index c323c713fa..f9b25b3f78 100644
--- a/gtk/gtktextbtree.c
+++ b/gtk/gtktextbtree.c
@@ -4146,7 +4146,12 @@ _gtk_text_line_char_to_byte_offsets (GtkTextLine *line,
{
const char *p;
- p = g_utf8_offset_to_pointer (seg->body.chars, offset);
+ /* if in the last fourth of the segment walk backwards */
+ if (seg->char_count - offset < seg->char_count / 4)
+ p = g_utf8_offset_to_pointer (seg->body.chars + seg->byte_count,
+ offset - seg->char_count);
+ else
+ p = g_utf8_offset_to_pointer (seg->body.chars, offset);
*seg_byte_offset = p - seg->body.chars;