word-wrap 0.3.1 → 0.3.2
raw patch · 3 files changed
+15/−20 lines, 3 files
Files
- CHANGELOG.md +6/−0
- src/Text/Wrap.hs +8/−19
- word-wrap.cabal +1/−1
CHANGELOG.md view
@@ -1,4 +1,10 @@ +0.3.2+=====++Bug fixes:+ * Fixed a bug that prevented wrapping sometimes.+ 0.3.1 =====
src/Text/Wrap.hs view
@@ -99,31 +99,20 @@ -- Take enough tokens until we reach the point where taking more -- would exceed the line length. let go _ [] = ([], [])- -- If the line contains a single token that itself exceeds the- -- limit, just take that single token as the only one on this- -- line.- go acc (tok:rest) | acc == 0 && tokenLength tok > limit =- case breakLongWords settings of- False -> ([tok], rest)- True ->- case tok of- WS _ -> ([], rest)- NonWS _ ->- let (h, tl) = T.splitAt limit (tokenContent tok)- in ([NonWS h], tokenize tl <> rest)- -- Otherwise take a token if its length plus the accumulator- -- doesn't exceed the limit. go acc (tok:toks) = if tokenLength tok + acc <= limit then let (nextAllowed, nextDisallowed) = go (acc + tokenLength tok) toks in (tok : nextAllowed, nextDisallowed)- else if not $ breakLongWords settings- then ([], (tok:toks))- else case tok of+ else case tok of WS _ -> ([], toks) NonWS _ ->- let (h, tl) = T.splitAt (limit - acc) (tokenContent tok)- in ([NonWS h], tokenize tl <> toks)+ if not $ breakLongWords settings+ then if acc == 0+ then ([tok], toks)+ else ([], tok:toks)+ else let remaining = max 0 (limit - acc)+ (h, tl) = T.splitAt remaining (tokenContent tok)+ in ([NonWS h], tokenize tl <> toks) -- Allowed tokens are the ones we keep on this line. The rest go -- on the next line, to be wrapped again.
word-wrap.cabal view
@@ -1,5 +1,5 @@ name: word-wrap-version: 0.3.1+version: 0.3.2 synopsis: A library for word-wrapping description: A library for wrapping long lines of text. license: BSD3