diff gtk/gtkimhtml.c @ 14338:2ec879353592

[gaim-migrate @ 17035] Fixes SF Bug # 1373116 (and related Debian Bug #341607) Fix the Find functionality in the log viewer. It now properly scrolls to the first occurrence of the search term. Also, clicking the Find button will now jump to the next occurrence of the search term, including wrapping around to the top. Possible Badness: This changes the behavior of all IMHTML searches. Previously, if you kept calling gtk_imhtml_search_find(), it'd clear the highlighting when you went past the last occurrence of the search term. This seems wrong. I believe it should either stop or wrap around to the top. Wrapping around seemed most useful to me, so that's what I implemented. This was inspired by SF Patch #1545488 by Mark Schneider committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 26 Aug 2006 06:25:49 +0000
parents cf8d25072151
children 737a6c286a65
line wrap: on
line diff
--- a/gtk/gtkimhtml.c	Fri Aug 25 23:59:23 2006 +0000
+++ b/gtk/gtkimhtml.c	Sat Aug 26 06:25:49 2006 +0000
@@ -3542,12 +3542,13 @@
 	imhtml->search_string = g_strdup(text);
 
 	if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
-					   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
-					 &start, &end, NULL)) {
-
+	                                   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
+	                                   &start, &end, NULL))
+	{
 		gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
 		gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
-		if (new_search) {
+		if (new_search)
+		{
 			gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end);
 			do
 				gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end);
@@ -3558,8 +3559,22 @@
 		}
 		return TRUE;
 	}
-
-	gtk_imhtml_search_clear(imhtml);
+	else if (!new_search)
+	{
+		/* We hit the end, so start at the beginning again. */
+		gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
+
+		if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
+		                                   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
+		                                   &start, &end, NULL))
+		{
+			gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
+			gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
+
+			return TRUE;
+		}
+
+	}
 
 	return FALSE;
 }