From a79faa602fac4e4bb4c33a324150219727fa1f57 Mon Sep 17 00:00:00 2001 From: Vadim Barkov Date: Sun, 8 Jan 2017 17:51:17 +0300 Subject: Fixed wrong behaviour of search on zero length results --- pluma/pluma-utils.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'pluma') diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index d1c701ea..b8f081c0 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -1597,6 +1597,9 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, gchar **all_matches; gchar *match_string; gboolean found; + gint non_null_result_number; + gboolean non_null_result_found; + guint result_size; compile_flags = 0; if ((flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) != 0) @@ -1645,9 +1648,38 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, if (found) { all_matches = g_match_info_fetch_all (match_info); + result_size = (gint) g_strv_length (all_matches); + + if(forward_search){ + non_null_result_number = 0; + } else { + non_null_result_number = result_size - 1 ; + } + non_null_result_found = FALSE; + while((non_null_result_number >= 0) + && (non_null_result_number < result_size) ) { + + if(g_utf8_strlen (all_matches [non_null_result_number], G_MAXSSIZE) != 0) { + non_null_result_found = TRUE; + break; + } else { + if(forward_search) { + non_null_result_number++; + } else { + non_null_result_number--; + } + } + + } + + if(!non_null_result_found) { + found = FALSE; + goto free_resources; + } + + match_string = all_matches [non_null_result_number]; if (forward_search) - { - match_string = all_matches[0]; + { gtk_text_iter_forward_search (begin_iter, match_string, flags, @@ -1656,8 +1688,7 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, limit); } else - { - match_string = all_matches[g_strv_length (all_matches) - 1]; + { gtk_text_iter_backward_search (begin_iter, match_string, flags, @@ -1667,6 +1698,7 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, } } +free_resources: gtk_text_iter_free (begin_iter); gtk_text_iter_free (end_iter); g_match_info_free (match_info); -- cgit v1.2.1