Ticket #1486: mc-4.7.0-pre1.completion.2.patch

File mc-4.7.0-pre1.completion.2.patch, 2.7 KB (added by dborca, 15 years ago)

Make sure we always get the closest match

  • edit/editcmd.c

    diff -Naur mc-4.7.0-pre1~/edit/editcmd.c mc-4.7.0-pre1/edit/editcmd.c
    old new  
    22712271    GString *temp; 
    22722272    mc_search_t *srch; 
    22732273 
     2274    long last_byte = start; 
     2275 
    22742276    srch = mc_search_new(match_expr, -1); 
    22752277    if (srch == NULL) 
    22762278        return 0; 
     
    22802282    srch->search_fn = edit_search_cmd_callback; 
    22812283 
    22822284    /* collect max MAX_WORD_COMPLETIONS completions */ 
    2283     start--; 
    2284     while (*num < MAX_WORD_COMPLETIONS) { 
     2285    start = -1; 
     2286    while (1) { 
    22852287        /* get next match */ 
    2286         if (mc_search_run (srch, (void *) edit, start+1, edit->last_byte, &len) == FALSE) 
     2288        if (mc_search_run (srch, (void *) edit, start+1, last_byte, &len) == FALSE) 
    22872289            break; 
    22882290        start = srch->normal_offset; 
    22892291 
     
    23052307                        (char *) &temp->str[word_len], 
    23062308                        max (len, compl[i].len) - word_len 
    23072309                    ) == 0) { 
     2310                struct selection this = compl[i]; 
     2311                for (++i; i < *num; i++) { 
     2312                    compl[i - 1] = compl[i]; 
     2313                } 
     2314                compl[*num - 1] = this; 
    23082315                skip = 1; 
    23092316                break;          /* skip it, already added */ 
    23102317            } 
     
    23132320            g_string_free(temp, TRUE); 
    23142321            continue; 
    23152322        } 
     2323        if (*num == MAX_WORD_COMPLETIONS && MAX_WORD_COMPLETIONS) { 
     2324            g_free(compl[0].text); 
     2325            for (i = 1; i < *num; i++) { 
     2326                compl[i - 1] = compl[i]; 
     2327            } 
     2328            (*num)--; 
     2329        } 
    23162330 
    23172331        compl[*num].text = temp->str; 
    23182332        compl[*num].len = temp->len; 
     
    23482362    bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE] 
    23492363        [word_start & M_EDIT_BUF_SIZE]; 
    23502364 
    2351     match_expr = g_strdup_printf ("(^|\\s)%.*s[^\\s\\.=\\+\\{\\}\\[\\]\\(\\)\\\\\\!\\,<>\\?\\/@#\\$%%\\^&\\*\\~\\|\\\"'\\:\\;]+", word_len, bufpos); 
     2365    match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); 
    23522366 
    23532367    /* collect the possible completions              */ 
    23542368    /* start search from begin to end of file */ 
    23552369    max_len = 
    2356         edit_collect_completions (edit, 0, word_len, match_expr, 
     2370        edit_collect_completions (edit, word_start, word_len, match_expr, 
    23572371                                  (struct selection *) &compl, &num_compl); 
    23582372 
    23592373    if (num_compl > 0) { 
  • edit/editcmd_dialogs.c

    diff -Naur mc-4.7.0-pre1~/edit/editcmd_dialogs.c mc-4.7.0-pre1/edit/editcmd_dialogs.c
    old new  
    296296    add_widget (compl_dlg, compl_list); 
    297297 
    298298    /* fill the listbox with the completions */ 
    299     for (i = 0; i < num_compl; i++) 
     299    for (i = num_compl - 1; i >= 0; i--) /* reverse order */ 
    300300        listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL); 
    301301 
    302302    /* pop up the dialog */