Ticket #3263: mcview hex: fix incorrect highlight when search string not found.

Restore previous string selection if search failed.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andreas Mohr 2015-02-18 13:38:41 +03:00 committed by Andrew Borodin
parent ef551ceaf2
commit 15cf75d63e
3 changed files with 18 additions and 10 deletions

View File

@ -99,14 +99,16 @@ mcview_remove_ext_script (mcview_t * view)
static void static void
mcview_search (mcview_t * view, gboolean start_search) mcview_search (mcview_t * view, gboolean start_search)
{ {
off_t want_search_start = view->search_start;
if (start_search) if (start_search)
{ {
if (mcview_dialog_search (view)) if (mcview_dialog_search (view))
{ {
if (view->hex_mode) 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 else
@ -114,14 +116,14 @@ mcview_search (mcview_t * view, gboolean start_search)
if (view->hex_mode) if (view->hex_mode)
{ {
if (!mcview_search_options.backwards) 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) else if (view->hex_cursor > 0)
view->search_start = view->hex_cursor - 1; want_search_start = view->hex_cursor - 1;
else else
view->search_start = 0; want_search_start = 0;
} }
mcview_do_search (view); mcview_do_search (view, want_search_start);
} }
} }

View File

@ -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, mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
int *current_char); int *current_char);
mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset); 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 ****************************************************************************/ /*** inline functions ****************************************************************************/

View File

@ -262,16 +262,18 @@ mcview_search_update_cmd_callback (const void *user_data, gsize char_offset)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
mcview_do_search (mcview_t * view) mcview_do_search (mcview_t * view, off_t want_search_start)
{ {
mcview_search_status_msg_t vsm; mcview_search_status_msg_t vsm;
off_t search_start = 0; off_t search_start = 0;
off_t orig_search_start = view->search_start;
gboolean isFound = FALSE; gboolean isFound = FALSE;
gboolean need_search_again = TRUE; gboolean need_search_again = TRUE;
size_t match_len; 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 */ /* for avoid infinite search loop we need to increase or decrease start offset of search */
if (view->search_start != 0) if (view->search_start != 0)
@ -352,6 +354,7 @@ mcview_do_search (mcview_t * view)
{ {
int result; int result;
view->search_start = orig_search_start;
mcview_update (view); mcview_update (view);
result = result =
@ -369,7 +372,7 @@ mcview_do_search (mcview_t * view)
/* continue search form beginning */ /* continue search form beginning */
off_t search_end; off_t search_end;
search_end = view->search_start; search_end = orig_search_start;
/* search_start is 0 here */ /* search_start is 0 here */
view->update_activate = search_start; view->update_activate = search_start;
@ -390,8 +393,11 @@ mcview_do_search (mcview_t * view)
} }
if (!isFound && view->search->error_str != NULL) 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")); query_dialog (_("Search"), view->search->error_str, D_NORMAL, 1, _("&Dismiss"));
}
view->dirty++; view->dirty++;
} }