Ticket #3263: mc-4.8.13-restore_prev_selection_if_search_failed.patch

File mc-4.8.13-restore_prev_selection_if_search_failed.patch, 3.6 KB (added by and, 5 years ago)

restore prev string selection if search failed

  • src/viewer/actions_cmd.c

    bugfix for ticket #3263 - mcview hex: Incorrect highlight when search string not found
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    
    diff -ruN mc-4.8.13/src/viewer/actions_cmd.c mc-4.8.13.patch/src/viewer/actions_cmd.c
    old new  
    9999static void 
    100100mcview_search (mcview_t * view, gboolean start_search) 
    101101{ 
     102    off_t want_search_start = view->search_start; 
     103 
    102104    if (start_search) 
    103105    { 
    104106        if (mcview_dialog_search (view)) 
    105107        { 
    106108            if (view->hex_mode) 
    107                 view->search_start = view->hex_cursor; 
     109                want_search_start = view->hex_cursor; 
    108110 
    109             mcview_do_search (view); 
     111            mcview_do_search (view,want_search_start); 
    110112        } 
    111113    } 
    112114    else 
     
    114116        if (view->hex_mode) 
    115117        { 
    116118            if (!mcview_search_options.backwards) 
    117                 view->search_start = view->hex_cursor + 1; 
     119                want_search_start = view->hex_cursor + 1; 
    118120            else if (view->hex_cursor > 0) 
    119                 view->search_start = view->hex_cursor - 1; 
     121                want_search_start = view->hex_cursor - 1; 
    120122            else 
    121                 view->search_start = 0; 
     123                want_search_start = 0; 
    122124        } 
    123125 
    124         mcview_do_search (view); 
     126        mcview_do_search (view,want_search_start); 
    125127    } 
    126128} 
    127129 
  • src/viewer/internal.h

    diff -ruN mc-4.8.13/src/viewer/internal.h mc-4.8.13.patch/src/viewer/internal.h
    old new  
    326326mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset, 
    327327                                              int *current_char); 
    328328mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset); 
    329 void mcview_do_search (mcview_t * view); 
     329void mcview_do_search (mcview_t * view, off_t); 
    330330 
    331331/*** inline functions ****************************************************************************/ 
    332332 
  • src/viewer/search.c

    diff -ruN mc-4.8.13/src/viewer/search.c mc-4.8.13.patch/src/viewer/search.c
    old new  
    262262/* --------------------------------------------------------------------------------------------- */ 
    263263 
    264264void 
    265 mcview_do_search (mcview_t * view) 
     265mcview_do_search (mcview_t * view, off_t want_search_start) 
    266266{ 
    267267    mcview_search_status_msg_t vsm; 
    268268 
    269269    off_t search_start = 0; 
     270    off_t orig_search_start = view->search_start; 
    270271    gboolean isFound = FALSE; 
    271272    gboolean need_search_again = TRUE; 
    272273 
    273274    size_t match_len; 
    274275 
     276    view->search_start = want_search_start; 
    275277    /* for avoid infinite search loop we need to increase or decrease start offset of search */ 
    276278 
    277279    if (view->search_start != 0) 
     
    352354    { 
    353355        int result; 
    354356 
     357        view->search_start = orig_search_start; 
    355358        mcview_update (view); 
    356359 
    357360        result = 
     
    369372        /* continue search form beginning */ 
    370373        off_t search_end; 
    371374 
    372         search_end = view->search_start; 
     375        search_end = orig_search_start; 
    373376        /* search_start is 0 here */ 
    374377        view->update_activate = search_start; 
    375378 
     
    390393    } 
    391394 
    392395    if (!isFound && view->search->error_str != NULL) 
     396    { 
     397        view->search_start = orig_search_start; 
     398        mcview_update (view); 
    393399        query_dialog (_("Search"), view->search->error_str, D_NORMAL, 1, _("&Dismiss")); 
    394  
     400    } 
    395401    view->dirty++; 
    396402} 
    397403