From 6604aa66f715121e1e5757fed84f31d60eddaad9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 7 Jul 2017 10:57:32 +0900 Subject: [PATCH] Treat non printable characters as zero-width instead of -1 width This fix a bug when opening a file where a line has a lot of unprintable chars (like a binary file) which was confusing Kakoune into considering that the line length in column was negative. --- src/unicode.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unicode.hh b/src/unicode.hh index ba340b3a..1355d687 100644 --- a/src/unicode.hh +++ b/src/unicode.hh @@ -55,7 +55,10 @@ inline bool is_basic_alpha(Codepoint c) noexcept inline ColumnCount codepoint_width(Codepoint c) noexcept { - return c == '\n' ? 1 : wcwidth((wchar_t)c); + if (c == '\n') + return 1; + const auto width = wcwidth((wchar_t)c); + return width > 0 ? width : 0; } enum class CharCategories