mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
reworked: edit_get_utf return int value is utf-8 char, char_width
This commit is contained in:
parent
7d7560deea
commit
d29c5d6d5f
37
edit/edit.c
37
edit/edit.c
@ -120,17 +120,44 @@ int edit_get_byte (WEdit * edit, long byte_index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *edit_get_utf_char (WEdit * edit, long byte_index)
|
int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
|
||||||
{
|
{
|
||||||
unsigned long p;
|
unsigned long p;
|
||||||
|
gunichar *str;
|
||||||
|
int res = -1;
|
||||||
|
gunichar ch;
|
||||||
|
gunichar *next_ch = NULL;
|
||||||
|
|
||||||
|
char_width = -1;
|
||||||
|
|
||||||
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
|
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (byte_index >= edit->curs1) {
|
if (byte_index >= edit->curs1) {
|
||||||
p = edit->curs1 + edit->curs2 - byte_index - 1;
|
p = edit->curs1 + edit->curs2 - byte_index - 1;
|
||||||
return str_get_next_char_safe (edit->buffers2[p >> S_EDIT_BUF_SIZE]+(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
|
str = (edit->buffers2[p >> S_EDIT_BUF_SIZE]+(EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1));
|
||||||
} else {
|
} else {
|
||||||
return str_get_next_char_safe (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE]+(byte_index & M_EDIT_BUF_SIZE));
|
str = (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE]+(byte_index & M_EDIT_BUF_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
res = g_utf8_get_char_validated (str, -1);
|
||||||
|
|
||||||
|
if ( res < 0 ) {
|
||||||
|
ch = (char) str;
|
||||||
|
char_width = 1;
|
||||||
|
} else {
|
||||||
|
ch = res;
|
||||||
|
next_ch = g_utf8_next_char(str);
|
||||||
|
if ( next_ch ) {
|
||||||
|
if ( next_ch != str ) {
|
||||||
|
char_width = next_ch - str;
|
||||||
|
} else {
|
||||||
|
char_width = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ch = 0;
|
||||||
|
char_width = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
|
|||||||
|
|
||||||
while (p->ch) {
|
while (p->ch) {
|
||||||
int style;
|
int style;
|
||||||
int textchar;
|
unsigned int textchar;
|
||||||
int color;
|
int color;
|
||||||
|
|
||||||
if (cols_to_skip) {
|
if (cols_to_skip) {
|
||||||
@ -292,6 +292,7 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
|||||||
|
|
||||||
long m1 = 0, m2 = 0, q, c1, c2;
|
long m1 = 0, m2 = 0, q, c1, c2;
|
||||||
int col, start_col_real;
|
int col, start_col_real;
|
||||||
|
int cw;
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
int color;
|
int color;
|
||||||
int i;
|
int i;
|
||||||
@ -335,8 +336,13 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
|||||||
if (q >= edit->found_start
|
if (q >= edit->found_start
|
||||||
&& q < edit->found_start + edit->found_len)
|
&& q < edit->found_start + edit->found_len)
|
||||||
p->style |= MOD_BOLD;
|
p->style |= MOD_BOLD;
|
||||||
c = edit_get_byte (edit, q);
|
cw = 1;
|
||||||
/* we don't use bg for mc - fg contains both */
|
if ( !edit->utf8 ) {
|
||||||
|
c = edit_get_byte (edit, q);
|
||||||
|
} else {
|
||||||
|
c = edit_get_utf (edit, q, &cw);
|
||||||
|
}
|
||||||
|
/* we don't use bg for mc - fg contains both */
|
||||||
edit_get_syntax_color (edit, q, &color);
|
edit_get_syntax_color (edit, q, &color);
|
||||||
p->style |= color << 16;
|
p->style |= color << 16;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -441,7 +447,10 @@ edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//FIXME: col += utfchar_width - 1
|
p->ch = c;
|
||||||
|
p++;
|
||||||
|
if ( cw > 1)
|
||||||
|
col += cw - 1;
|
||||||
}
|
}
|
||||||
col++;
|
col++;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user