Ticket #257: 00-84-utf8-complete.patch

File 00-84-utf8-complete.patch, 2.3 KB (added by egmont, 15 years ago)

Fix completion

  • src/complete.c

    Make completion work if the command line already has some accented characters.
    
    diff -Naurdp mc-4.6.1.orig/src/complete.c mc-4.6.1/src/complete.c
    old new static int insert_text (WInput *in, char 
    797797            *p = 0; 
    798798        } 
    799799        memcpy (in->buffer + start, text, len - start + end); 
    800         in->point += len; 
     800        in->point += mbstrnlen(text - start + end, len); 
    801801        update_input (in, 1); 
    802802        end += len; 
    803803    } 
    complete_engine (WInput *in, int what_to 
    912912    if (in->completions && in->point != end) 
    913913        free_completions (in); 
    914914    if (!in->completions){ 
    915         end = in->point; 
     915        end = columns_to_bytes(in->buffer, in->point); 
    916916        for (start = end ? end - 1 : 0; start > -1; start--) 
    917917            if (strchr (" \t;|<>", in->buffer [start])) 
    918918                break; 
  • src/util.c

    diff -Naurdp mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
    old new mbstrlen (const char *str) 
    139139        return strlen (str); 
    140140} 
    141141 
     142size_t 
     143mbstrnlen (const char *str, size_t maxlen) 
     144{ 
     145#ifdef UTF8 
     146    if (1) { 
     147        size_t width = 0; 
     148 
     149        for (; *str && maxlen; str++, maxlen--) { 
     150            wchar_t c; 
     151            size_t len; 
     152 
     153            len = mbrtowc (&c, str, maxlen > MB_CUR_MAX ? MB_CUR_MAX : maxlen, NULL); 
     154             
     155            if (len == (size_t)(-1) || len == (size_t)(-2)) break; 
     156             
     157            if (len > 0) { 
     158                int wcsize = wcwidth(c); 
     159                width += wcsize >= 0 ? wcsize : 1; 
     160                str += len-1; 
     161            } 
     162        } 
     163 
     164        return width; 
     165    } else 
     166#endif 
     167        return strnlen (str, maxlen); 
     168} 
     169 
    142170int 
    143171columns_to_bytes (const char *str, int col) 
    144172{ 
  • src/util.h

    diff -Naurdp mc-4.6.1.orig/src/util.h mc-4.6.1/src/util.h
    old new char *get_owner (int); 
    9595 
    9696void fix_utf8(char *str); 
    9797size_t mbstrlen (const char *); 
     98size_t mbstrnlen (const char *, size_t); 
    9899int columns_to_bytes (const char *, int); 
    99100wchar_t *mbstr_to_wchar (const char *); 
    100101char *wchar_to_mbstr (const wchar_t *);