changeset 13478:38dcde2c8c4b

[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 <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 09 Mar 2006 06:26:16 +0000
parents d18f5962d454
children 90740e70af91
files src/gtkblist.c
diffstat 1 files changed, 55 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);