# HG changeset patch # User Richard Laager # Date 1141885576 0 # Node ID 38dcde2c8c4ba2af5cec9aed795b13e963768f14 # Parent d18f5962d454c71e7698dfaa73fea3281fd73a60 [gaim-migrate @ 15854] Make the type-ahead search in the buddy list only match on the beginning of words. Fixes SF Bug Report #1442845 Major thanks to behdad from #gtk+ on irc.gnome.org for help walking me through the Pango code. committer: Tailor Script diff -r d18f5962d454 -r 38dcde2c8c4b src/gtkblist.c --- a/src/gtkblist.c Thu Mar 09 04:04:54 2006 +0000 +++ b/src/gtkblist.c Thu Mar 09 06:26:16 2006 +0000 @@ -3375,11 +3375,15 @@ static gboolean _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) { - gboolean result; gchar *enteredstring; gchar *withmarkup; gchar *nomarkup; gchar *normalized; + gboolean result; + size_t i; + size_t len; + PangoLogAttr *log_attrs; + gchar *word; gtk_tree_model_get(model, iter, column, &withmarkup, -1); @@ -3387,7 +3391,56 @@ nomarkup = gaim_markup_strip_html(withmarkup); normalized = g_utf8_casefold(gaim_normalize(NULL, nomarkup), -1); - result = (g_strstr_len(normalized, strlen(normalized), enteredstring) == NULL); + if (gaim_str_has_prefix(normalized, enteredstring)) + { + g_free(withmarkup); + g_free(enteredstring); + g_free(nomarkup); + g_free(normalized); + return FALSE; + } + + + /* Use Pango to separate by words. */ + len = g_utf8_strlen(normalized, -1); + log_attrs = g_new(PangoLogAttr, len + 1); + + pango_get_log_attrs(normalized, len, -1, NULL, log_attrs, len + 1); + + word = normalized; + result = TRUE; + for (i = 0; i < (len - 1) ; i++) + { + if (log_attrs[i].is_word_start && + gaim_str_has_prefix(word, enteredstring)) + { + result = FALSE; + break; + } + word = g_utf8_next_char(word); + } + g_free(log_attrs); + +/* The non-Pango version. */ +#if 0 + word = normalized; + result = TRUE; + while (word[0] != '\0') + { + gunichar c = g_utf8_get_char(word); + if (!g_unichar_isalnum(c)) + { + word = g_utf8_find_next_char(word, NULL); + if (gaim_str_has_prefix(word, enteredstring)) + { + result = FALSE; + break; + } + } + else + word = g_utf8_find_next_char(word, NULL); + } +#endif g_free(withmarkup); g_free(enteredstring);