summaryrefslogtreecommitdiff
path: root/pluma/pluma-document.c
diff options
context:
space:
mode:
Diffstat (limited to 'pluma/pluma-document.c')
-rw-r--r--pluma/pluma-document.c124
1 files changed, 83 insertions, 41 deletions
diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c
index 8634636f..ecc7f424 100644
--- a/pluma/pluma-document.c
+++ b/pluma/pluma-document.c
@@ -116,6 +116,7 @@ struct _PlumaDocumentPrivate
guint search_flags;
gchar *search_text;
+ gchar *last_replace_text;
gint num_of_lines_search_text;
PlumaDocumentNewlineType newline_type;
@@ -301,6 +302,7 @@ pluma_document_finalize (GObject *object)
g_free (doc->priv->uri);
g_free (doc->priv->content_type);
g_free (doc->priv->search_text);
+ g_free (doc->priv->last_replace_text);
if (doc->priv->to_search_region != NULL)
{
@@ -1864,6 +1866,35 @@ pluma_document_get_search_text (PlumaDocument *doc,
return pluma_utils_escape_search_text (doc->priv->search_text);
}
+/**
+ * pluma_document_set_last_replace_text:
+ * @doc:
+ * @text: (allow-none):
+ **/
+void
+pluma_document_set_last_replace_text (PlumaDocument *doc,
+ const gchar *text)
+{
+ g_return_if_fail (PLUMA_IS_DOCUMENT (doc));
+
+ g_free(doc->priv->last_replace_text);
+
+ pluma_debug_message (DEBUG_SEARCH, "last_replace_text = %s", text == NULL ? "NULL" : text);
+ doc->priv->last_replace_text = g_strdup(text);
+}
+
+/**
+ * pluma_document_get_last_replace_text:
+ * @doc:
+ */
+gchar *
+pluma_document_get_last_replace_text (PlumaDocument *doc)
+{
+ g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), NULL);
+
+ return doc->priv->last_replace_text;
+}
+
gboolean
pluma_document_get_can_search_again (PlumaDocument *doc)
{
@@ -1922,22 +1953,23 @@ pluma_document_search_forward (PlumaDocument *doc,
while (!found)
{
- if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags))
+ if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags))
{
- found = gtk_text_iter_forward_search (&iter,
- doc->priv->search_text,
- search_flags,
- &m_start,
- &m_end,
- end);
- }else{
- found = pluma_gtk_text_iter_regex_search (&iter,
- doc->priv->search_text,
- search_flags,
- &m_start,
- &m_end,
- end,
- TRUE);
+ found = gtk_text_iter_forward_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ end);
+ } else {
+ found = pluma_gtk_text_iter_regex_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ end,
+ TRUE,
+ &doc->priv->last_replace_text);
}
if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
@@ -1971,10 +2003,10 @@ pluma_document_search_forward (PlumaDocument *doc,
**/
gboolean
pluma_document_search_backward (PlumaDocument *doc,
- const GtkTextIter *start,
- const GtkTextIter *end,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end)
{
GtkTextIter iter;
GtkTextSearchFlags search_flags;
@@ -2027,7 +2059,8 @@ pluma_document_search_backward (PlumaDocument *doc,
&m_start,
&m_end,
end,
- FALSE);
+ FALSE,
+ &doc->priv->last_replace_text);
}
if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
@@ -2065,7 +2098,7 @@ pluma_document_replace_all (PlumaDocument *doc,
gboolean found = TRUE;
gint cont = 0;
gchar *search_text;
- gchar *replace_text;
+ gchar *replace_text = NULL;
gint replace_text_len;
GtkTextBuffer *buffer;
gboolean brackets_highlighting;
@@ -2082,7 +2115,11 @@ pluma_document_replace_all (PlumaDocument *doc,
else
search_text = pluma_utils_unescape_search_text (find);
- replace_text = pluma_utils_unescape_search_text (replace);
+ if(!PLUMA_SEARCH_IS_MATCH_REGEX(flags))
+ {
+ replace_text = pluma_utils_unescape_search_text (replace);
+ replace_text_len = strlen (replace_text);
+ }
gtk_text_buffer_get_start_iter (buffer, &iter);
@@ -2093,7 +2130,6 @@ pluma_document_replace_all (PlumaDocument *doc,
search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;
}
- replace_text_len = strlen (replace_text);
/* disable cursor_moved emission until the end of the
* replace_all so that we don't spend all the time
@@ -2113,23 +2149,28 @@ pluma_document_replace_all (PlumaDocument *doc,
do
{
- 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(!PLUMA_SEARCH_IS_MATCH_REGEX(flags))
+ {
+ found = gtk_text_iter_forward_search (&iter,
+ search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ NULL);
+ } else {
+ if(replace_text != NULL)
+ g_free (replace_text);
+ replace_text = g_strdup (replace);
+ found = pluma_gtk_text_iter_regex_search (&iter,
+ search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ NULL,
+ TRUE,
+ &replace_text);
+ replace_text_len = strlen (replace_text);
+ }
if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (flags))
{
@@ -2175,7 +2216,8 @@ pluma_document_replace_all (PlumaDocument *doc,
pluma_document_set_enable_search_highlighting (doc, search_highliting);
g_free (search_text);
- g_free (replace_text);
+ if(replace_text != NULL)
+ g_free (replace_text);
return cont;
}