takeColumns: take even zero-width characters as long as possible

This change makes it so that takeColumns (which is used by 'str' to
account for the widths of Unicode characters) will continue taking
characters that do not exhaust the allowed width, meaning that it will
now take zero-width characters. Previously it stopped taking characters
as soon as it exhausted the allowed width and that meant it would ignore
zero-width characters following that point.
This commit is contained in:
Jonathan Daugherty 2020-04-27 09:06:55 -07:00
parent 8b5021ff4e
commit 9ab39545a2

View File

@ -236,11 +236,9 @@ takeColumns :: Int -> String -> String
takeColumns _ "" = ""
takeColumns numCols (c:cs) =
let w = V.safeWcwidth c
in if w == numCols
then [c]
else if w < numCols
then c : takeColumns (numCols - w) cs
else ""
in if w > numCols
then []
else c : takeColumns (numCols - w) cs
-- | Make a widget from a string, but wrap the words in the input's
-- lines at the available width using the default wrapping settings. The