From f5040532c5d7b675c8681da390d5b3f5d31cf1fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 11 Nov 2017 09:29:28 +0530 Subject: [PATCH] Ensure combining chars are zero-width regardless of wcwidth implementation --- kitty/screen.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitty/screen.c b/kitty/screen.c index e6b6b552a..1d6a3952a 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -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); }