From 0487daf8655c8a353d2804fad7ffc7c5cf22f0a2 Mon Sep 17 00:00:00 2001 From: RichardHitt Date: Tue, 18 Feb 2014 02:20:30 -0800 Subject: Fix three miscellaneous bugs in gtk_xtext_get_word() * Use utf8 functions for moving within string * Fix memory leak * Fix non-indent select problem --- src/fe-gtk/xtext.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c index 6a6b1215..ff28d25d 100644 --- a/src/fe-gtk/xtext.c +++ b/src/fe-gtk/xtext.c @@ -1499,41 +1499,43 @@ gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent, textentry *ent; int offset; unsigned char *word; + unsigned char *last, *end; int len; int out_of_bounds = 0; int len_to_offset = 0; ent = gtk_xtext_find_char (xtext, x, y, &offset, &out_of_bounds); - if (!ent) - return 0; - - if (out_of_bounds) - return 0; - - if (offset == ent->str_len) - return 0; - - if (offset < 1) - return 0; - - /*offset--;*/ /* FIXME: not all chars are 1 byte */ + if (ent == NULL || out_of_bounds || offset < 0 || offset >= ent->str_len) + return NULL; word = ent->str + offset; - - while (!is_del (*word) && word != ent->str) + while ((word = g_utf8_find_prev_char (ent->str, word))) { - word--; - len_to_offset++; + if (is_del (*word)) + { + word++; + len_to_offset--; + break; + } + len_to_offset += charlen (word); } - word++; - len_to_offset--; + if (!word) + word = ent->str; /* remove color characters from the length */ - gtk_xtext_strip_color (word, len_to_offset, xtext->scratch_buffer, &len_to_offset, slp, FALSE); + gtk_xtext_strip_color (word, len_to_offset, xtext->scratch_buffer, &len_to_offset, NULL, FALSE); + last = word; + end = ent->str + ent->str_len; len = 0; - while (!is_del (word[len]) && len != ent->str_len) - len++; + do + { + if (is_del (*last)) + break; + len += charlen (last); + last = g_utf8_find_next_char (last, end); + } + while (last); if (len > 0 && word[len-1]=='.') len--; -- cgit 1.4.1