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 |
797 | 797 | *p = 0; |
798 | 798 | } |
799 | 799 | memcpy (in->buffer + start, text, len - start + end); |
800 | | in->point += len; |
| 800 | in->point += mbstrnlen(text - start + end, len); |
801 | 801 | update_input (in, 1); |
802 | 802 | end += len; |
803 | 803 | } |
… |
… |
complete_engine (WInput *in, int what_to |
912 | 912 | if (in->completions && in->point != end) |
913 | 913 | free_completions (in); |
914 | 914 | if (!in->completions){ |
915 | | end = in->point; |
| 915 | end = columns_to_bytes(in->buffer, in->point); |
916 | 916 | for (start = end ? end - 1 : 0; start > -1; start--) |
917 | 917 | if (strchr (" \t;|<>", in->buffer [start])) |
918 | 918 | break; |
diff -Naurdp mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
old
|
new
|
mbstrlen (const char *str) |
139 | 139 | return strlen (str); |
140 | 140 | } |
141 | 141 | |
| 142 | size_t |
| 143 | mbstrnlen (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 | |
142 | 170 | int |
143 | 171 | columns_to_bytes (const char *str, int col) |
144 | 172 | { |
diff -Naurdp mc-4.6.1.orig/src/util.h mc-4.6.1/src/util.h
old
|
new
|
char *get_owner (int); |
95 | 95 | |
96 | 96 | void fix_utf8(char *str); |
97 | 97 | size_t mbstrlen (const char *); |
| 98 | size_t mbstrnlen (const char *, size_t); |
98 | 99 | int columns_to_bytes (const char *, int); |
99 | 100 | wchar_t *mbstr_to_wchar (const char *); |
100 | 101 | char *wchar_to_mbstr (const wchar_t *); |