ex_getln: Clean up draw_cmdline a bit

This commit is contained in:
ZyX
2017-03-26 01:34:13 +03:00
parent 2b377d89db
commit 90f62cc749

View File

@@ -2174,69 +2174,64 @@ void free_cmdline_buf(void)
*/ */
static void draw_cmdline(int start, int len) static void draw_cmdline(int start, int len)
{ {
int i; if (cmdline_star > 0) {
for (int i = 0; i < len; i++) {
if (cmdline_star > 0)
for (i = 0; i < len; ++i) {
msg_putchar('*'); msg_putchar('*');
if (has_mbyte) if (has_mbyte) {
i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1;
} }
else if (p_arshape && !p_tbidi && enc_utf8 && len > 0) { }
} else if (p_arshape && !p_tbidi && enc_utf8 && len > 0) {
static int buflen = 0; static int buflen = 0;
char_u *p;
int j;
int newlen = 0;
int mb_l;
int pc, pc1 = 0;
int prev_c = 0;
int prev_c1 = 0;
int u8c;
int u8cc[MAX_MCO];
int nc = 0;
/* // Do arabic shaping into a temporary buffer. This is very
* Do arabic shaping into a temporary buffer. This is very // inefficient!
* inefficient!
*/
if (len * 2 + 2 > buflen) { if (len * 2 + 2 > buflen) {
/* Re-allocate the buffer. We keep it around to avoid a lot of // Re-allocate the buffer. We keep it around to avoid a lot of
* alloc()/free() calls. */ // alloc()/free() calls.
xfree(arshape_buf); xfree(arshape_buf);
buflen = len * 2 + 2; buflen = len * 2 + 2;
arshape_buf = xmalloc(buflen); arshape_buf = xmalloc(buflen);
} }
int newlen = 0;
if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) {
/* Prepend a space to draw the leading composing char on. */ // Prepend a space to draw the leading composing char on.
arshape_buf[0] = ' '; arshape_buf[0] = ' ';
newlen = 1; newlen = 1;
} }
for (j = start; j < start + len; j += mb_l) { int mb_l;
p = ccline.cmdbuff + j; int prev_c = 0;
u8c = utfc_ptr2char_len(p, u8cc, start + len - j); int prev_c1 = 0;
mb_l = utfc_ptr2len_len(p, start + len - j); for (int i = start; i < start + len; i += mb_l) {
char_u *p = ccline.cmdbuff + i;
int u8cc[MAX_MCO];
int u8c = utfc_ptr2char_len(p, u8cc, start + len - i);
mb_l = utfc_ptr2len_len(p, start + len - i);
if (arabic_char(u8c)) { if (arabic_char(u8c)) {
/* Do Arabic shaping. */ int pc;
int pc1 = 0;
int nc = 0;
// Do Arabic shaping.
if (cmdmsg_rl) { if (cmdmsg_rl) {
/* displaying from right to left */ // Displaying from right to left.
pc = prev_c; pc = prev_c;
pc1 = prev_c1; pc1 = prev_c1;
prev_c1 = u8cc[0]; prev_c1 = u8cc[0];
if (j + mb_l >= start + len) if (i + mb_l >= start + len) {
nc = NUL; nc = NUL;
else
nc = utf_ptr2char(p + mb_l);
} else { } else {
/* displaying from left to right */ nc = utf_ptr2char(p + mb_l);
if (j + mb_l >= start + len) }
} else {
// Displaying from left to right.
if (i + mb_l >= start + len) {
pc = NUL; pc = NUL;
else { } else {
int pcc[MAX_MCO]; int pcc[MAX_MCO];
pc = utfc_ptr2char_len(p + mb_l, pcc, pc = utfc_ptr2char_len(p + mb_l, pcc, start + len - i - mb_l);
start + len - j - mb_l);
pc1 = pcc[0]; pc1 = pcc[0];
} }
nc = prev_c; nc = prev_c;
@@ -2260,9 +2255,10 @@ static void draw_cmdline(int start, int len)
} }
msg_outtrans_len(arshape_buf, newlen); msg_outtrans_len(arshape_buf, newlen);
} else } else {
msg_outtrans_len(ccline.cmdbuff + start, len); msg_outtrans_len(ccline.cmdbuff + start, len);
} }
}
/* /*
* Put a character on the command line. Shifts the following text to the * Put a character on the command line. Shifts the following text to the