Fix three miscellaneous bugs in gtk_xtext_get_word()

* Use utf8 functions for moving within string
	* Fix memory leak
	* Fix non-indent select problem
This commit is contained in:
RichardHitt 2014-02-18 02:20:30 -08:00 committed by TingPing
parent 99ee7b6ef8
commit 0487daf865
1 changed files with 24 additions and 22 deletions

View File

@ -1499,41 +1499,43 @@ gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent,
textentry *ent; textentry *ent;
int offset; int offset;
unsigned char *word; unsigned char *word;
unsigned char *last, *end;
int len; int len;
int out_of_bounds = 0; int out_of_bounds = 0;
int len_to_offset = 0; int len_to_offset = 0;
ent = gtk_xtext_find_char (xtext, x, y, &offset, &out_of_bounds); ent = gtk_xtext_find_char (xtext, x, y, &offset, &out_of_bounds);
if (!ent) if (ent == NULL || out_of_bounds || offset < 0 || offset >= ent->str_len)
return 0; return NULL;
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 */
word = ent->str + offset; word = ent->str + offset;
while ((word = g_utf8_find_prev_char (ent->str, word)))
while (!is_del (*word) && word != ent->str)
{ {
word--; if (is_del (*word))
len_to_offset++; {
word++;
len_to_offset--;
break;
}
len_to_offset += charlen (word);
} }
word++; if (!word)
len_to_offset--; word = ent->str;
/* remove color characters from the length */ /* 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; len = 0;
while (!is_del (word[len]) && len != ent->str_len) do
len++; {
if (is_del (*last))
break;
len += charlen (last);
last = g_utf8_find_next_char (last, end);
}
while (last);
if (len > 0 && word[len-1]=='.') if (len > 0 && word[len-1]=='.')
len--; len--;