WEditor 0.2.0.2 → 0.2.1.0
raw patch · 5 files changed
+25/−4 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ WEditor.Base.Char: isDefaultHyphen :: HyphenChar c => c -> Bool
+ WEditor.LineWrap: endsWithHyphen :: WordSplitter s c => s -> [c] -> Bool
Files
- ChangeLog.md +5/−0
- WEditor.cabal +1/−1
- WEditor/Base/Char.hs +4/−1
- WEditor/LineWrap.hs +9/−2
- test/TestLineWrap.hs +6/−0
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for WEditor +## 0.2.1.0 -- 2020-04-20++* **[new]** Fixes an issue with hyphenating words that already have hyphens by+ adding `endsWithHyphen` to `WordSplitter`.+ ## 0.2.0.0 -- 2020-04-17 * **[breaking]** Adds line-splitting to `FixedFontParser` requirements. This
WEditor.cabal view
@@ -1,5 +1,5 @@ name: WEditor-version: 0.2.0.2+version: 0.2.1.0 synopsis: Generic text-editor logic for use with fixed-width fonts. description:
WEditor/Base/Char.hs view
@@ -43,12 +43,15 @@ class HyphenChar c where -- | The canonical hyphen character. defaultHyphen :: c+ isDefaultHyphen :: c -> Bool+ isDefaultHyphen _ = False instance WhitespaceChar Char where defaultIsWhitespace = (== ' ') instance WordChar Char where- defaultIsWordChar = flip any [isAlpha,(`elem` ".'")] . flip ($)+ defaultIsWordChar = flip any [isAlpha,(`elem` ".'-")] . flip ($) instance HyphenChar Char where defaultHyphen = '-'+ isDefaultHyphen = (== defaultHyphen)
WEditor/LineWrap.hs view
@@ -102,6 +102,9 @@ -- | Append the canonical hyphen character to show word breaks. appendHyphen :: s -> [c] -> [c] appendHyphen _ = id+ -- | Check the word segment for an existing hyphenation.+ endsWithHyphen :: s -> [c] -> Bool+ endsWithHyphen _ _ = False -- | Wrapping policy that breaks lines based on words. Use 'breakWords' to -- construct a new value.@@ -154,6 +157,7 @@ isWordChar _ = defaultIsWordChar isWhitespace _ = defaultIsWhitespace appendHyphen _ = (++[defaultHyphen])+ endsWithHyphen _ cs = not (null cs) && isDefaultHyphen (last cs) instance FixedFontParser (BreakWords c) c where type BreakType (BreakWords c) = LineBreak@@ -197,14 +201,17 @@ when (null breaks && length wordFront == w) Nothing return $ case breaks of [] -> VisibleLine lineBreakSimple (reverse ls2):(breakOrEmpty (word ++ rs2))- (b:bs) -> VisibleLine lineBreakHyphen (reverse ls2 ++ take b word):(hyphenate (drop b word) bs)+ (b:bs) -> (autoHyphen (reverse ls2 ++ take b word)):(hyphenate (drop b word) bs) ls2 = dropWhile (isWordChar s) ls rs2 = dropWhile (isWordChar s) rs wordFront = reverse $ takeWhile (isWordChar s) ls wordBack = takeWhile (isWordChar s) rs word = wordFront ++ wordBack+ autoHyphen ls = if endsWithHyphen s ls+ then VisibleLine lineBreakSimple ls+ else VisibleLine lineBreakHyphen ls hyphenate word bs | null word || null bs = breakOrEmpty (word ++ rs2)- hyphenate word (b:bs) = (VisibleLine lineBreakHyphen (take b word)):(hyphenate (drop b word) bs)+ hyphenate word (b:bs) = (autoHyphen (take b word)):(hyphenate (drop b word) bs) tryWord _ _ = Nothing trySpaces ls rs@(r:_) | isWhitespace s r = newLines where ls' = reverse ls ++ takeWhile (isWhitespace s) rs
test/TestLineWrap.hs view
@@ -153,6 +153,12 @@ hyphenLine "aver", hyphenLine "ylon", endLine "gword"]),+ ("lazyHyphen skips redundant hyphen", checkLineBreak+ (setLineWidth (breakWords lazyHyphen) 6)+ "here-isalongword"+ [innerLine "here-",+ hyphenLine "isalo",+ endLine "ngword"]), ("lazyHyphen preserves data", do let breaker = setLineWidth (breakWords lazyHyphen) 7 let line = "Here are some extra spaces and alongwordthatwillnotfit. "