packages feed

text-zipper 0.3.1 → 0.4

raw patch · 2 files changed

+20/−7 lines, 2 files

Files

src/Data/Text/Zipper.hs view
@@ -17,6 +17,7 @@     , mkZipper     , textZipper     , stringZipper+    , clearZipper     , vectorZipper     , getText     , currentLine@@ -155,9 +156,12 @@                , toRight = drop_ tz col (t !! row)                } -lastLine :: TextZipper a -> Bool-lastLine = (== 0) . length . below+isFirstLine :: TextZipper a -> Bool+isFirstLine = null . above +isLastLine :: TextZipper a -> Bool+isLastLine = (== 0) . length . below+ nextLine :: TextZipper a -> a nextLine = head . below @@ -281,7 +285,7 @@ moveUp :: (Monoid a) => TextZipper a -> TextZipper a moveUp tz     -- Is there a line above at least as long as the current one?-    | (not $ null (above tz)) &&+    | (not $ isFirstLine tz) &&       (length_ tz $ last $ above tz) >= length_ tz (toLeft tz) =         tz { below = currentLine tz : below tz            , above = init $ above tz@@ -289,7 +293,7 @@            , toRight = drop_ tz (length_ tz $ toLeft tz) (last $ above tz)            }     -- Or if there is a line above, just go to the end of it-    | (not $ null (above tz)) =+    | (not $ isFirstLine tz) =         tz { above = init $ above tz            , below = currentLine tz : below tz            , toLeft = last $ above tz@@ -304,7 +308,7 @@ moveDown :: (Monoid a) => TextZipper a -> TextZipper a moveDown tz     -- Is there a line below at least as long as the current one?-    | (not $ lastLine tz) &&+    | (not $ isLastLine tz) &&       (length_ tz $ nextLine tz) >= length_ tz (toLeft tz) =         tz { below = tail $ below tz            , above = above tz ++ [currentLine tz]@@ -312,7 +316,7 @@            , toRight = drop_ tz (length_ tz $ toLeft tz) (nextLine tz)            }     -- Or if there is a line below, just go to the end of it-    | (not $ null (below tz)) =+    | (not $ isLastLine tz) =         tz { above = above tz ++ [currentLine tz]            , below = tail $ below tz            , toLeft = nextLine tz@@ -330,6 +334,15 @@ vectorZipper :: [V.Vector Char] -> Maybe Int -> TextZipper (V.Vector Char) vectorZipper =     mkZipper V.singleton V.drop V.take V.length V.last V.init V.null++-- |Empty a zipper.+clearZipper :: (Monoid a) => TextZipper a -> TextZipper a+clearZipper tz =+    tz { toLeft = mempty+       , toRight = mempty+       , above = []+       , below = []+       }  -- |Construct a zipper from 'T.Text' values. textZipper :: [T.Text] -> Maybe Int -> TextZipper T.Text
text-zipper.cabal view
@@ -1,5 +1,5 @@ name:                text-zipper-version:             0.3.1+version:             0.4 synopsis:            A text editor zipper library description:         This library provides a zipper and API for editing text. license:             BSD3