mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
Merge pull request #19847 from lewis6991/utfmb
refactor(drawline.c): factor out utf8 multibyte check
This commit is contained in:
@@ -449,6 +449,16 @@ static void apply_cursorline_highlight(win_T *wp, linenr_T lnum, int *line_attr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool check_mb_utf8(int *c, int *u8cc)
|
||||||
|
{
|
||||||
|
if (utf_char2len(*c) > 1) {
|
||||||
|
*u8cc = 0;
|
||||||
|
*c = 0xc0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Display line "lnum" of window 'wp' on the screen.
|
/// Display line "lnum" of window 'wp' on the screen.
|
||||||
/// wp->w_virtcol needs to be valid.
|
/// wp->w_virtcol needs to be valid.
|
||||||
///
|
///
|
||||||
@@ -1460,13 +1470,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
if (c_extra != NUL || (n_extra == 1 && c_final != NUL)) {
|
if (c_extra != NUL || (n_extra == 1 && c_final != NUL)) {
|
||||||
c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
|
c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
|
||||||
mb_c = c; // doesn't handle non-utf-8 multi-byte!
|
mb_c = c; // doesn't handle non-utf-8 multi-byte!
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
assert(p_extra != NULL);
|
assert(p_extra != NULL);
|
||||||
c = *p_extra;
|
c = *p_extra;
|
||||||
@@ -1855,13 +1859,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
extra_attr = win_hl_attr(wp, HLF_0);
|
extra_attr = win_hl_attr(wp, HLF_0);
|
||||||
saved_attr2 = char_attr; // save current attr
|
saved_attr2 = char_attr; // save current attr
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
|
if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
|
||||||
@@ -1884,13 +1882,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
extra_attr = win_hl_attr(wp, HLF_0);
|
extra_attr = win_hl_attr(wp, HLF_0);
|
||||||
saved_attr2 = char_attr; // save current attr
|
saved_attr2 = char_attr; // save current attr
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2004,11 +1996,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
extra_attr = win_hl_attr(wp, HLF_0);
|
extra_attr = win_hl_attr(wp, HLF_0);
|
||||||
saved_attr2 = char_attr; // save current attr
|
saved_attr2 = char_attr; // save current attr
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
c_final = NUL;
|
c_final = NUL;
|
||||||
c_extra = ' ';
|
c_extra = ' ';
|
||||||
@@ -2051,13 +2039,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
extra_attr = win_hl_attr(wp, HLF_AT);
|
extra_attr = win_hl_attr(wp, HLF_AT);
|
||||||
n_attr = 1;
|
n_attr = 1;
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false; // don't draw as UTF-8
|
|
||||||
}
|
|
||||||
} else if (c != NUL) {
|
} else if (c != NUL) {
|
||||||
p_extra = transchar_buf(wp->w_buffer, c);
|
p_extra = transchar_buf(wp->w_buffer, c);
|
||||||
if (n_extra == 0) {
|
if (n_extra == 0) {
|
||||||
@@ -2148,13 +2130,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
n_skip = 1;
|
n_skip = 1;
|
||||||
}
|
}
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false; // don't draw as UTF-8
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prev_syntax_id = 0;
|
prev_syntax_id = 0;
|
||||||
is_concealing = false;
|
is_concealing = false;
|
||||||
@@ -2208,13 +2184,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
extra_attr = win_hl_attr(wp, HLF_AT);
|
extra_attr = win_hl_attr(wp, HLF_AT);
|
||||||
}
|
}
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false; // don't draw as UTF-8
|
|
||||||
}
|
|
||||||
saved_attr3 = char_attr; // save current attr
|
saved_attr3 = char_attr; // save current attr
|
||||||
char_attr = win_hl_attr(wp, HLF_AT); // overwriting char_attr
|
char_attr = win_hl_attr(wp, HLF_AT); // overwriting char_attr
|
||||||
n_attr3 = 1;
|
n_attr3 = 1;
|
||||||
@@ -2424,13 +2394,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
|||||||
c = wp->w_p_lcs_chars.ext;
|
c = wp->w_p_lcs_chars.ext;
|
||||||
char_attr = win_hl_attr(wp, HLF_AT);
|
char_attr = win_hl_attr(wp, HLF_AT);
|
||||||
mb_c = c;
|
mb_c = c;
|
||||||
if (utf_char2len(c) > 1) {
|
mb_utf8 = check_mb_utf8(&c, u8cc);
|
||||||
mb_utf8 = true;
|
|
||||||
u8cc[0] = 0;
|
|
||||||
c = 0xc0;
|
|
||||||
} else {
|
|
||||||
mb_utf8 = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance to the next 'colorcolumn'
|
// advance to the next 'colorcolumn'
|
||||||
|
Reference in New Issue
Block a user