compute correct width for whitespace characters that will be replaced v_0 v0.15
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 29 Nov 2019 22:34:57 +0100
branchv_0
changeset 27 f03e1f9cfcb6
parent 26 32824e833b89
child 28 2e51eb540e01
compute correct width for whitespace characters that will be replaced
src/TabularPrefetchingHandler.h
--- a/src/TabularPrefetchingHandler.h	Sun Nov 17 17:51:13 2019 +0100
+++ b/src/TabularPrefetchingHandler.h	Fri Nov 29 22:34:57 2019 +0100
@@ -80,6 +80,7 @@
 		result << convertor.from_bytes(color);
 
 		for (auto & ch : value) {
+			// see computeWidth below
 			switch (ch) {
 				case L'\n': result << colorizeReplacement(L"↲", color);
 					break;
@@ -104,7 +105,19 @@
 	 */
 	integer_t computeWidth(const string_t& stringValue) {
 		integer_t width = 0;
-		for (wchar_t ch : stringValue) width += std::max(0, wcwidth(ch));
+		for (wchar_t ch : stringValue) {
+			// see formatValue() above
+			switch (ch) {
+				case L'\n':
+				case L'\r':
+				case L'\t':
+				case L' ':
+					width += 1;
+					break;
+				default:
+					width += std::max(0, wcwidth(ch));
+			}
+		}
 		return width;
 	}