summaryrefslogtreecommitdiff
path: root/pluma/pluma-commands-search.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2013-11-04 02:26:08 -0800
committerStefano Karapetsas <[email protected]>2013-11-04 02:26:08 -0800
commitbdec76d8f1f2b2b844436c1c07d9d8803e2356c6 (patch)
tree58ba3b84c8dfe628b740f5fcdd20aff4d6be2c7f /pluma/pluma-commands-search.c
parent70a9d462ec240b59bab82bc46ac60f64cb801a40 (diff)
parent1bf710e2a1addeada225b94006d3479ccdc43230 (diff)
downloadpluma-bdec76d8f1f2b2b844436c1c07d9d8803e2356c6.tar.bz2
pluma-bdec76d8f1f2b2b844436c1c07d9d8803e2356c6.tar.xz
Merge pull request #24 from bl0ckeduser/master
Fix search/replace of strings containing backslashes
Diffstat (limited to 'pluma/pluma-commands-search.c')
-rw-r--r--pluma/pluma-commands-search.c99
1 files changed, 86 insertions, 13 deletions
diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c
index 7e15357e..01780f42 100644
--- a/pluma/pluma-commands-search.c
+++ b/pluma/pluma-commands-search.c
@@ -234,6 +234,7 @@ do_find (PlumaSearchDialog *dialog,
gboolean entire_word;
gboolean wrap_around;
gboolean search_backwards;
+ gboolean parse_escapes;
guint flags = 0;
guint old_flags = 0;
gboolean found;
@@ -246,12 +247,17 @@ do_find (PlumaSearchDialog *dialog,
doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
- entry_text = pluma_search_dialog_get_search_text (dialog);
-
match_case = pluma_search_dialog_get_match_case (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);
+ parse_escapes = pluma_search_dialog_get_parse_escapes (dialog);
+
+ if (!parse_escapes) {
+ entry_text = pluma_utils_escape_search_text (pluma_search_dialog_get_search_text (dialog));
+ } else {
+ entry_text = pluma_search_dialog_get_search_text (dialog);
+ }
PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
@@ -273,8 +279,13 @@ do_find (PlumaSearchDialog *dialog,
if (found)
text_found (window, 0);
- else
- text_not_found (window, entry_text);
+ else {
+ if (!parse_escapes) {
+ text_not_found (window, pluma_utils_unescape_search_text (entry_text));
+ } else {
+ text_not_found (window, entry_text);
+ }
+ }
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
PLUMA_SEARCH_DIALOG_REPLACE_RESPONSE,
@@ -335,17 +346,27 @@ do_replace (PlumaSearchDialog *dialog,
gchar *unescaped_replace_text;
gchar *selected_text = NULL;
gboolean match_case;
+ gboolean parse_escapes;
doc = pluma_window_get_active_document (window);
if (doc == NULL)
return;
- search_entry_text = pluma_search_dialog_get_search_text (dialog);
+ parse_escapes = pluma_search_dialog_get_parse_escapes (dialog);
+ if (!parse_escapes) {
+ search_entry_text = pluma_utils_escape_search_text (pluma_search_dialog_get_search_text (dialog));
+ } else {
+ search_entry_text = pluma_search_dialog_get_search_text (dialog);
+ }
g_return_if_fail ((search_entry_text) != NULL);
g_return_if_fail ((*search_entry_text) != '\0');
/* replace text may be "", we just delete */
- replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
+ if (!parse_escapes) {
+ replace_entry_text = pluma_utils_escape_search_text (pluma_search_dialog_get_replace_text (dialog));
+ } else {
+ replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
+ }
g_return_if_fail ((replace_entry_text) != NULL);
unescaped_search_text = pluma_utils_unescape_search_text (search_entry_text);
@@ -390,6 +411,7 @@ do_replace_all (PlumaSearchDialog *dialog,
const gchar *replace_entry_text;
gboolean match_case;
gboolean entire_word;
+ gboolean parse_escapes;
guint flags = 0;
gint count;
@@ -399,12 +421,21 @@ do_replace_all (PlumaSearchDialog *dialog,
doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
- search_entry_text = pluma_search_dialog_get_search_text (dialog);
+ parse_escapes = pluma_search_dialog_get_parse_escapes (dialog);
+ if (!parse_escapes) {
+ search_entry_text = pluma_utils_escape_search_text(pluma_search_dialog_get_search_text (dialog));
+ } else {
+ search_entry_text = pluma_search_dialog_get_search_text (dialog);
+ }
g_return_if_fail ((search_entry_text) != NULL);
g_return_if_fail ((*search_entry_text) != '\0');
/* replace text may be "", we just delete all occurrencies */
- replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
+ if (!parse_escapes) {
+ replace_entry_text = pluma_utils_escape_search_text (pluma_search_dialog_get_replace_text (dialog));
+ } else {
+ replace_entry_text = pluma_search_dialog_get_replace_text (dialog);
+ }
g_return_if_fail ((replace_entry_text) != NULL);
match_case = pluma_search_dialog_get_match_case (dialog);
@@ -424,7 +455,11 @@ do_replace_all (PlumaSearchDialog *dialog,
}
else
{
- text_not_found (window, search_entry_text);
+ if (!parse_escapes) {
+ text_not_found (window, pluma_utils_unescape_search_text (search_entry_text));
+ } else {
+ text_not_found (window, search_entry_text);
+ }
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
@@ -516,7 +551,9 @@ _pluma_cmd_search_find (GtkAction *action,
GtkWidget *search_dialog;
PlumaDocument *doc;
gboolean selection_exists;
+ gboolean parse_escapes;
gchar *find_text = NULL;
+ const gchar *search_text = NULL;
gint sel_len;
pluma_debug (DEBUG_COMMANDS);
@@ -548,8 +585,25 @@ _pluma_cmd_search_find (GtkAction *action,
if (selection_exists && find_text != NULL && sel_len < 80)
{
- pluma_search_dialog_set_search_text (PLUMA_SEARCH_DIALOG (search_dialog),
- find_text);
+ /*
+ * Special case: if the currently selected text
+ * is the same as the unescaped search text and
+ * escape sequence parsing is activated, use the
+ * same old search text. (Without this, if you e.g.
+ * search for '\n' in escaped mode and then open
+ * the search dialog again, you'll get an unprintable
+ * single-character literal '\n' in the "search for"
+ * box).
+ */
+ parse_escapes = pluma_search_dialog_get_parse_escapes (PLUMA_SEARCH_DIALOG (search_dialog));
+ search_text = pluma_search_dialog_get_search_text (PLUMA_SEARCH_DIALOG (search_dialog));
+ if (!(search_text != NULL
+ && !strcmp(pluma_utils_unescape_search_text(search_text), find_text)
+ && parse_escapes)) {
+ /* General case */
+ pluma_search_dialog_set_search_text (PLUMA_SEARCH_DIALOG (search_dialog),
+ find_text);
+ }
g_free (find_text);
}
else
@@ -571,7 +625,9 @@ _pluma_cmd_search_replace (GtkAction *action,
GtkWidget *replace_dialog;
PlumaDocument *doc;
gboolean selection_exists;
+ gboolean parse_escapes;
gchar *find_text = NULL;
+ const gchar *search_text = NULL;
gint sel_len;
pluma_debug (DEBUG_COMMANDS);
@@ -603,8 +659,25 @@ _pluma_cmd_search_replace (GtkAction *action,
if (selection_exists && find_text != NULL && sel_len < 80)
{
- pluma_search_dialog_set_search_text (PLUMA_SEARCH_DIALOG (replace_dialog),
- find_text);
+ /*
+ * Special case: if the currently selected text
+ * is the same as the unescaped search text and
+ * escape sequence parsing is activated, use the
+ * same old search text. (Without this, if you e.g.
+ * search for '\n' in escaped mode and then open
+ * the search dialog again, you'll get an unprintable
+ * single-character literal '\n' in the "search for"
+ * box).
+ */
+ parse_escapes = pluma_search_dialog_get_parse_escapes (PLUMA_SEARCH_DIALOG (replace_dialog));
+ search_text = pluma_search_dialog_get_search_text (PLUMA_SEARCH_DIALOG (replace_dialog));
+ if (!(search_text != NULL
+ && !strcmp(pluma_utils_unescape_search_text(search_text), find_text)
+ && parse_escapes)) {
+ /* General case */
+ pluma_search_dialog_set_search_text (PLUMA_SEARCH_DIALOG (replace_dialog),
+ find_text);
+ }
g_free (find_text);
}
else