on master help sign in
Improve cropping behavior with zero-width characters
commit5f6bb0f24fa7b042f443a312dc094d5961e77037 authorEric Mertens <emertens@gmail.com> dateThu 1 Sep 2016, 10:14 (10 years ago) parent818eed2
1 file changed+5−4
src/Graphics/Vty/Image/Internal.hs+5−4
src/Graphics/Vty/Image/Internal.hs+5−4
@@ -38,12 +38,13 @@ clipText txt leftSkip rightClip =
3838 txt' = if padPrefix then TL.cons '…' (TL.drop (toDrop+1) txt) else TL.drop toDrop txt
3939 (toTake,padSuffix) = clipForCharWidth rightClip txt' 0
4040 txt'' = TL.append (TL.take toTake txt') (if padSuffix then TL.singleton '…' else TL.empty)
41− clipForCharWidth 0 _ n = (n, False)
41+ -- Note: some characters and zero-width and combining characters
42+ -- combine to the left, so keep taking characters even if the width
43+ -- is zero.
4244 clipForCharWidth w t n
4345 | TL.null t = (n, False)
44− | w < cw = (n, True)
45− | w == cw = (n+1, False)
46− | w > cw = clipForCharWidth (w - cw) (TL.tail t) (n + 1)
46+ | w < cw = (n, w /= 0)
47+ | otherwise = clipForCharWidth (w - cw) (TL.tail t) (n + 1)
4748 where cw = safeWcwidth (TL.head t)
4849 clipForCharWidth _ _ _ = error "clipForCharWidth applied to undefined"
4950 in txt''