mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
fix: edit_draw_this_line iterators. iterators += utf8char_width
fix: edit.c edit_get_utf correct calculate utf8char width
This commit is contained in:
parent
d29c5d6d5f
commit
f45e7d1dc6
26
edit/edit.c
26
edit/edit.c
@ -123,15 +123,16 @@ int edit_get_byte (WEdit * edit, long byte_index)
|
||||
int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
|
||||
{
|
||||
unsigned long p;
|
||||
gunichar *str;
|
||||
gchar *str = NULL;
|
||||
int res = -1;
|
||||
gunichar ch;
|
||||
gunichar *next_ch = NULL;
|
||||
gchar *next_ch = NULL;
|
||||
int width = 0;
|
||||
|
||||
char_width = -1;
|
||||
|
||||
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
|
||||
return NULL;
|
||||
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) {
|
||||
*char_width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (byte_index >= edit->curs1) {
|
||||
p = edit->curs1 + edit->curs2 - byte_index - 1;
|
||||
@ -143,22 +144,25 @@ int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if ( res < 0 ) {
|
||||
ch = (char) str;
|
||||
char_width = 1;
|
||||
ch = *str;
|
||||
width = 1;
|
||||
} else {
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char(str);
|
||||
if ( next_ch ) {
|
||||
if ( next_ch != str ) {
|
||||
char_width = next_ch - str;
|
||||
width = next_ch - str;
|
||||
} else {
|
||||
char_width = -1;
|
||||
width = 0;
|
||||
}
|
||||
} else {
|
||||
ch = 0;
|
||||
char_width = -1;
|
||||
width = 0;
|
||||
}
|
||||
}
|
||||
*char_width = width;
|
||||
return ch;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -318,6 +318,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
||||
}
|
||||
|
||||
while (col <= end_col - edit->start_col) {
|
||||
mc_log("col=%i, end_col = %i, edit->start_col = %i, end_col - edit->start_col = %i\n",col, end_col, edit->start_col,end_col - edit->start_col );
|
||||
p->ch = 0;
|
||||
p->style = 0;
|
||||
if (q == edit->curs1)
|
||||
@ -341,6 +342,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
||||
c = edit_get_byte (edit, q);
|
||||
} else {
|
||||
c = edit_get_utf (edit, q, &cw);
|
||||
mc_log("c:%04x, w:%i\n", c, cw);
|
||||
}
|
||||
/* we don't use bg for mc - fg contains both */
|
||||
edit_get_syntax_color (edit, q, &color);
|
||||
@ -449,13 +451,18 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
||||
} else {
|
||||
p->ch = c;
|
||||
p++;
|
||||
if ( cw > 1)
|
||||
if ( cw > 1) {
|
||||
col += cw - 1;
|
||||
mc_log("col+ : %i\n", cw-1);
|
||||
}
|
||||
}
|
||||
col++;
|
||||
break;
|
||||
}
|
||||
q++;
|
||||
if ( cw > 1) {
|
||||
q += cw - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user