fix [#34275] Text autocomplete cuts words with accents or special characters

autocomplete is now unicode aware, using python api's checks for now. eventually we should have our own.
This commit is contained in:
Campbell Barton 2013-02-19 16:13:41 +00:00
parent 91a63e347d
commit 7f1ae2497b
4 changed files with 36 additions and 3 deletions

@ -109,6 +109,10 @@ int text_check_identifier_nodigit(const char ch);
int text_check_whitespace(const char ch);
int text_find_identifier_start(const char *str, int i);
/* defined in bpy_interface.c */
extern int text_check_identifier_unicode(const unsigned int ch);
extern int text_check_identifier_nodigit_unicode(const unsigned int ch);
enum {
TXT_MOVE_LINE_UP = -1,
TXT_MOVE_LINE_DOWN = 1

@ -2938,6 +2938,18 @@ int text_check_identifier_nodigit(const char ch)
return 0;
}
#ifndef WITH_PYTHON
int text_check_identifier_unicode(const unsigned int ch)
{
return (ch < 255 && text_check_identifier((char)ch));
}
int text_check_identifier_nodigit_unicode(const unsigned int ch)
{
return (ch < 255 && text_check_identifier_nodigit((char)ch));
}
#endif /* WITH_PYTHON */
int text_check_whitespace(const char ch)
{
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')

@ -170,13 +170,13 @@ static GHash *text_autocomplete_build(Text *text)
/* seek identifier beginning */
i_pos = i_start;
while ((i_start < linep->len) &&
(!text_check_identifier_nodigit(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_start], &i_pos))))
(!text_check_identifier_nodigit_unicode(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_start], &i_pos))))
{
i_start = i_pos;
}
i_pos = i_end = i_start;
while ((i_end < linep->len) &&
(text_check_identifier(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_end], &i_pos))))
(text_check_identifier_unicode(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_end], &i_pos))))
{
i_end = i_pos;
}
@ -184,7 +184,7 @@ static GHash *text_autocomplete_build(Text *text)
if ((i_start != i_end) &&
/* check we're at the beginning of a line or that the previous char is not an identifier
* this prevents digits from being added */
((i_start < 1) || !text_check_identifier(BLI_str_utf8_as_unicode(&linep->line[i_start - 1]))))
((i_start < 1) || !text_check_identifier_unicode(BLI_str_utf8_as_unicode(&linep->line[i_start - 1]))))
{
char *str_sub = &linep->line[i_start];
const int choice_len = i_end - i_start;

@ -928,3 +928,20 @@ static void bpy_module_free(void *UNUSED(mod))
}
#endif
/* EVIL, define text.c functions here... */
extern int text_check_identifier_unicode(const unsigned int ch);
extern int text_check_identifier_nodigit_unicode(const unsigned int ch);
extern int text_check_identifier(const char ch);
extern int text_check_identifier_nodigit(const char ch);
int text_check_identifier_unicode(const unsigned int ch)
{
return (ch < 255 && text_check_identifier((char)ch)) || Py_UNICODE_ISALNUM(ch);
}
int text_check_identifier_nodigit_unicode(const unsigned int ch)
{
return (ch < 255 && text_check_identifier_nodigit((char)ch)) || Py_UNICODE_ISALPHA(ch);
}