Ensure combining chars are zero-width regardless of wcwidth implementation

This commit is contained in:
Kovid Goyal 2017-11-11 09:29:28 +05:30
parent 447a2fe8cf
commit f5040532c5
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -271,7 +271,8 @@ void
screen_draw(Screen *self, uint32_t och) {
if (is_ignored_char(och)) return;
uint32_t ch = och < 256 ? self->g_charset[och] : och;
unsigned int char_width = safe_wcwidth(ch);
bool is_cc = is_combining_char(ch);
unsigned int char_width = is_cc ? 0 : safe_wcwidth(ch);
if (self->columns - self->cursor->x < char_width) {
if (self->modes.mDECAWM) {
screen_carriage_return(self);
@ -1289,7 +1290,11 @@ screen_wcswidth(Screen UNUSED *self, PyObject *str) {
void *data = PyUnicode_DATA(str);
Py_ssize_t len = PyUnicode_GET_LENGTH(str), i;
unsigned long ans = 0;
for (i = 0; i < len; i++) ans += safe_wcwidth(PyUnicode_READ(kind, data, i));
for (i = 0; i < len; i++) {
char_type ch = PyUnicode_READ(kind, data, i);
bool is_cc = is_combining_char(ch);
ans += is_cc ? 0 : safe_wcwidth(ch);
}
return PyLong_FromUnsignedLong(ans);
}