packages feed

word-wrap 0.4 → 0.4.1

raw patch · 4 files changed

+38/−4 lines, 4 files

Files

CHANGELOG.md view
@@ -1,4 +1,24 @@ +0.4.1+=====++Bug fixes:+ * Fixed a bug that caused breakTokens to diverge for lines with+   indentation longer than the indentation width when+   preserveIndentation was enabled. (Thanks Callum Oakley.) The+   resulting fix does the following:+   * When breakLongWords is enabled, this change reduces the indentation+     of the indented lines to result in lines that are no longer than+     the wrap limit, so they will have reduced indentation and word+     fragments. This is a trade-off with other options that are open to+     evaluation.+   * When breakLongWords is disabled, this change reduces the+     indentation of the indented lines and leaves whole words, unbroken,+     on them, resulting in lines that are longer than the indentation+     limit. This behavior is similar to non-indented lines with+     over-long tokens. This is also a trade-off with other options that+     are open to evaluation.+ 0.4 === 
src/Text/Wrap.hs view
@@ -82,9 +82,9 @@                 Nothing -> [firstLineText]                 Just rest -> firstLineText : go lim rest         (indent, modifiedText) = if preserveIndentation settings-                         then let i = T.takeWhile isSpace t-                              in (i, T.drop (T.length i) t)-                         else (T.empty, t)+                                 then let i = T.takeWhile isSpace t+                                      in (T.take (limit - 1) i, T.drop (T.length i) t)+                                 else (T.empty, t)         result = go (limit - T.length indent) (tokenize modifiedText)     in (indent <>) <$> result 
tests/Main.hs view
@@ -50,3 +50,17 @@         `shouldBe` [ "  Hello", "  Crazy", "  World", "  !"                    , "  Reall", "  yLong", "  Token"                    ]++    it "gracefully handles indentation longer than the target width when breaking is off" $ do+      let s = defaultWrapSettings { breakLongWords = False+                                  , preserveIndentation = True+                                  }+      wrapTextToLines s 4 "           foo bar"+        `shouldBe` ["   foo", "   bar"]++    it "gracefully handles indentation longer than the target width when breaking is on" $ do+      let s = defaultWrapSettings { breakLongWords = True+                                  , preserveIndentation = True+                                  }+      wrapTextToLines s 4 "           foo bar"+        `shouldBe` ["   f", "   o", "   o", "   b", "   a", "   r"]
word-wrap.cabal view
@@ -1,5 +1,5 @@ name:                word-wrap-version:             0.4+version:             0.4.1 synopsis:            A library for word-wrapping description:         A library for wrapping long lines of text. license:             BSD3