From 29f4e11f08ef02d6a3c6623b8a445502e3e98ed6 Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Sun, 20 Nov 2016 19:28:02 +0300 Subject: Implemented "replace all" behavior for regexp --- pluma/pluma-commands-search.c | 3 +++ pluma/pluma-document.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 6903d381..393b088a 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -431,6 +431,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; @@ -460,9 +461,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, diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 43abf989..11ad1372 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -2009,12 +2009,12 @@ pluma_document_search_backward (PlumaDocument *doc, { if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); + found = gtk_text_iter_backward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + start); } else{ found = pluma_gtk_text_iter_regex_search (&iter, @@ -2109,12 +2109,23 @@ pluma_document_replace_all (PlumaDocument *doc, do { - found = gtk_text_iter_forward_search (&iter, - search_text, - search_flags, - &m_start, - &m_end, - NULL); + if(!PLUMA_SEARCH_IS_MATCH_REGEX(flags)) + { + found = gtk_text_iter_forward_search (&iter, + search_text, + search_flags, + &m_start, + &m_end, + NULL); + }else{ + found = pluma_gtk_text_iter_regex_search (&iter, + search_text, + search_flags, + &m_start, + &m_end, + NULL, + TRUE); + } if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (flags)) { @@ -2143,7 +2154,7 @@ pluma_document_replace_all (PlumaDocument *doc, replace_text_len); iter = m_start; - } + } } while (found); -- cgit v1.2.1