diff options
Diffstat (limited to 'pluma/pluma-commands-search.c')
-rw-r--r-- | pluma/pluma-commands-search.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 1a75dbca..f4db2479 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -227,6 +227,7 @@ do_find (PlumaSearchDialog *dialog, gchar *search_text; const gchar *entry_text; gboolean match_case; + gboolean match_regex; gboolean entire_word; gboolean wrap_around; gboolean search_backwards; @@ -244,6 +245,7 @@ do_find (PlumaSearchDialog *dialog, doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); entire_word = pluma_search_dialog_get_entire_word (dialog); search_backwards = pluma_search_dialog_get_backwards (dialog); wrap_around = pluma_search_dialog_get_wrap_around (dialog); @@ -257,6 +259,7 @@ do_find (PlumaSearchDialog *dialog, PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); search_text = pluma_document_get_search_text (doc, &old_flags); @@ -342,7 +345,9 @@ do_replace (PlumaSearchDialog *dialog, gchar *unescaped_replace_text; gchar *selected_text = NULL; gboolean match_case; + gboolean match_regex; gboolean parse_escapes; + gboolean need_refind; doc = pluma_window_get_active_document (window); if (doc == NULL) @@ -372,17 +377,36 @@ do_replace (PlumaSearchDialog *dialog, NULL); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); + + if (selected_text != NULL) + { + if(!match_regex) + { + need_refind = (match_case && (strcmp (selected_text,unescaped_search_text) != 0)) + || (!match_case && !g_utf8_caselessnmatch (selected_text, + unescaped_search_text, + strlen (selected_text), + strlen (unescaped_search_text)) != 0); + } + else + { + need_refind = !g_regex_match_simple(unescaped_search_text, + selected_text, + match_case ? 0 : GTK_TEXT_SEARCH_CASE_INSENSITIVE , + 0); + } + } + else + { + need_refind = TRUE; + } - if ((selected_text == NULL) || - (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || - (!match_case && !g_utf8_caselessnmatch (selected_text, - unescaped_search_text, - strlen (selected_text), - strlen (unescaped_search_text)) != 0)) + if (need_refind) { do_find (dialog, window); g_free (unescaped_search_text); - g_free (selected_text); + g_free (selected_text); return; } @@ -406,6 +430,7 @@ do_replace_all (PlumaSearchDialog *dialog, const gchar *search_entry_text; const gchar *replace_entry_text; gboolean match_case; + gboolean match_regex; gboolean entire_word; gboolean parse_escapes; guint flags = 0; @@ -435,9 +460,11 @@ do_replace_all (PlumaSearchDialog *dialog, g_return_if_fail ((replace_entry_text) != NULL); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); entire_word = pluma_search_dialog_get_entire_word (dialog); PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); count = pluma_document_replace_all (doc, |