From 15cf75d63ef47900dbdeff0b82320f848e38855e Mon Sep 17 00:00:00 2001 From: Andreas Mohr Date: Wed, 18 Feb 2015 13:38:41 +0300 Subject: [PATCH] Ticket #3263: mcview hex: fix incorrect highlight when search string not found. Restore previous string selection if search failed. Signed-off-by: Andrew Borodin --- src/viewer/actions_cmd.c | 14 ++++++++------ src/viewer/internal.h | 2 +- src/viewer/search.c | 12 +++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index f0143086d..bf837162c 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -99,14 +99,16 @@ mcview_remove_ext_script (mcview_t * view) static void mcview_search (mcview_t * view, gboolean start_search) { + off_t want_search_start = view->search_start; + if (start_search) { if (mcview_dialog_search (view)) { if (view->hex_mode) - view->search_start = view->hex_cursor; + want_search_start = view->hex_cursor; - mcview_do_search (view); + mcview_do_search (view, want_search_start); } } else @@ -114,14 +116,14 @@ mcview_search (mcview_t * view, gboolean start_search) if (view->hex_mode) { if (!mcview_search_options.backwards) - view->search_start = view->hex_cursor + 1; + want_search_start = view->hex_cursor + 1; else if (view->hex_cursor > 0) - view->search_start = view->hex_cursor - 1; + want_search_start = view->hex_cursor - 1; else - view->search_start = 0; + want_search_start = 0; } - mcview_do_search (view); + mcview_do_search (view, want_search_start); } } diff --git a/src/viewer/internal.h b/src/viewer/internal.h index d8c39cfa0..0676518f3 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -350,7 +350,7 @@ int mcview_nroff_seq_prev (mcview_nroff_t *); mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char); mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset); -void mcview_do_search (mcview_t * view); +void mcview_do_search (mcview_t * view, off_t want_search_start); /*** inline functions ****************************************************************************/ diff --git a/src/viewer/search.c b/src/viewer/search.c index 783a485cb..915bb8562 100644 --- a/src/viewer/search.c +++ b/src/viewer/search.c @@ -262,16 +262,18 @@ mcview_search_update_cmd_callback (const void *user_data, gsize char_offset) /* --------------------------------------------------------------------------------------------- */ void -mcview_do_search (mcview_t * view) +mcview_do_search (mcview_t * view, off_t want_search_start) { mcview_search_status_msg_t vsm; off_t search_start = 0; + off_t orig_search_start = view->search_start; gboolean isFound = FALSE; gboolean need_search_again = TRUE; size_t match_len; + view->search_start = want_search_start; /* for avoid infinite search loop we need to increase or decrease start offset of search */ if (view->search_start != 0) @@ -352,6 +354,7 @@ mcview_do_search (mcview_t * view) { int result; + view->search_start = orig_search_start; mcview_update (view); result = @@ -369,7 +372,7 @@ mcview_do_search (mcview_t * view) /* continue search form beginning */ off_t search_end; - search_end = view->search_start; + search_end = orig_search_start; /* search_start is 0 here */ view->update_activate = search_start; @@ -390,8 +393,11 @@ mcview_do_search (mcview_t * view) } if (!isFound && view->search->error_str != NULL) + { + view->search_start = orig_search_start; + mcview_update (view); query_dialog (_("Search"), view->search->error_str, D_NORMAL, 1, _("&Dismiss")); - + } view->dirty++; }