diff options
author | bl0ckeduser <[email protected]> | 2013-09-22 12:06:08 -0400 |
---|---|---|
committer | bl0ckeduser <[email protected]> | 2013-09-22 12:07:41 -0400 |
commit | 1bf710e2a1addeada225b94006d3479ccdc43230 (patch) | |
tree | b8d90c80965233e11d24945c45ff04429bb71e2d | |
parent | 24dc1853b70b34301034c28e2d0a0e2bb416e8f6 (diff) | |
download | pluma-1bf710e2a1addeada225b94006d3479ccdc43230.tar.bz2 pluma-1bf710e2a1addeada225b94006d3479ccdc43230.tar.xz |
Gracefully handle a rare search/replace special case
-rw-r--r-- | pluma/pluma-commands-search.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 4c92b65e..d6a75ef2 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -546,7 +546,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); @@ -578,8 +580,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 @@ -601,7 +620,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); @@ -633,8 +654,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 |