Ticket #2372 (Editor sometimes shows multibyte UTF-8 chars as two dots)

Sometimes when text contain multibyte UTF-8 chars, editor shows two dots instead of some letter.
When moving text cursor after that letter it will be displayed properly.
When moving cursor back (before letter) it will be displayed again as two dots.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>

added UTF8_CHAR_LEN

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Sergey 2011-10-15 12:42:43 +00:00 committed by Ilia Maslakov
parent 8fd8c23a49
commit 3e1b644f41
2 changed files with 13 additions and 0 deletions

View File

@ -128,6 +128,7 @@
#define SCRIPT_SUFFIX ""
#define get_default_editor() "vi"
#define OS_SORT_CASE_SENSITIVE_DEFAULT 1
#define UTF8_CHAR_LEN 6
/* C++ style type casts */
#define const_cast(m_type, m_expr) ((m_type) (m_expr))

View File

@ -1949,6 +1949,7 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width)
gunichar ch;
gchar *next_ch = NULL;
int width = 0;
gchar utf8_buf[UTF8_CHAR_LEN + 1];
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
{
@ -1966,6 +1967,17 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width)
res = g_utf8_get_char_validated (str, -1);
if (res < 0)
{
/* Retry with explicit bytes to make sure it's not a buffer boundary */
int i;
for (i = 0; i < UTF8_CHAR_LEN; i++)
utf8_buf[i] = edit_get_byte (edit, byte_index + i);
utf8_buf[UTF8_CHAR_LEN] = '\0';
str = utf8_buf;
res = g_utf8_get_char_validated (str, -1);
}
if (res < 0)
{
ch = *str;