on develop help sign in
address comments
commit53abc346e8dbd64b9089542884fcf8149de300fb authorpdlla <chippermonky@gmail.com> dateThu 1 Jul 2021, 11:46 (5 years ago) parente012570
2 files changed+5−1
src/Data/Text/Zipper.hs+2−1 test/Data/Text/ZipperSpec.hs+3
src/Data/Text/Zipper.hs+2−1
@@ -365,6 +365,7 @@ wrapWithOffsetAndAlignment
365365 -> [WrappedLine] -- (words on that line, hidden space char, offset from beginning of line)
366366wrapWithOffsetAndAlignment _ maxWidth _ _ | maxWidth <= 0 = []
367367wrapWithOffsetAndAlignment alignment maxWidth n txt = assert (n <= maxWidth) r where
368+ -- we pad by offset amount with any non-space character which we will remove later so that no changes need to be made to splitWordsAtDisplayWidth
368369 r' = splitWordsAtDisplayWidth maxWidth $ wordsWithWhitespace ( T.replicate n "." <> txt)
369370 fmapfn (t,b) = case alignment of
370371 TextAlignment_Left -> WrappedLine t b 0
@@ -378,7 +379,7 @@ wrapWithOffsetAndAlignment alignment maxWidth n txt = assert (n <= maxWidth) r w
378379
379380-- converts deleted eol spaces into logical lines
380381eolSpacesToLogicalLines :: [[WrappedLine]] -> [[(Text, Int)]]
381−eolSpacesToLogicalLines = fmap (fmap (\(WrappedLine a _ c) -> (a,c))) . ((L.groupBy (\(WrappedLine _ b _) _ -> not b)) =<<)
382+eolSpacesToLogicalLines = fmap (fmap (\(WrappedLine a _ c) -> (a,c))) . concatMap (L.groupBy (\(WrappedLine _ b _) _ -> not b))
382383
383384offsetMapWithAlignmentInternal :: [[WrappedLine]] -> OffsetMapWithAlignment
384385offsetMapWithAlignmentInternal = offsetMapWithAlignment . eolSpacesToLogicalLines
test/Data/Text/ZipperSpec.hs+3
@@ -40,6 +40,9 @@ spec =
4040 wrapWithOffsetAndAlignment TextAlignment_Right 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 1), (WrappedLine "12" False 3)]
4141 wrapWithOffsetAndAlignment TextAlignment_Center 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 1)]
4242 wrapWithOffsetAndAlignment TextAlignment_Left 5 1 someSentence `shouldBe` [(WrappedLine "1234" False 0), (WrappedLine "5" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
43+
44+ -- leading spaces and offset case
45+ wrapWithOffsetAndAlignment TextAlignment_Left 5 1 (" " <> someSentence) `shouldBe` [(WrappedLine " " True 0), (WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
4346 it "eolSpacesToLogicalLines" $ do
4447 eolSpacesToLogicalLines
4548 [