From 72fef55675134871c70e416966c8a0ea2aca34ba Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Dec 2015 13:17:09 -0500 Subject: [PATCH] Adjoin expects breaks at the end of lines. --- src/Split.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Split.hs b/src/Split.hs index 7e23b5a37..38950a13e 100644 --- a/src/Split.hs +++ b/src/Split.hs @@ -188,18 +188,18 @@ maybeLast list = listToMaybe $ reverse list adjoin2 :: [Row] -> Row -> [Row] adjoin2 [] row = [row] --- handle the case where we append a newline on both sides -adjoin2 rows (Row left@(Line (Break : _)) right@(Line (Break : _))) = Row left right : rows -adjoin2 rows (Row left@(Line (Break : _)) right) = Row left EmptyLine : zipWith Row lefts rights - where - lefts = leftLines rows - rights = adjoin2Lines (rightLines rows) right -adjoin2 rows (Row left right@(Line (Break : _))) = Row EmptyLine right : zipWith Row lefts rights - where - lefts = adjoin2Lines (leftLines rows) left - rights = rightLines rows -adjoin2 (Row EmptyLine EmptyLine : init) row = adjoin2 init row +adjoin2 rows@(Row left right:_) row | Just Break <- maybeLast $ unLine left, Just Break <- maybeLast $ unLine right = row : rows + +adjoin2 rows@(Row left _:_) (Row left' right') | Just Break <- maybeLast $ unLine left = Row left' EmptyLine : zipWith Row lefts rights + where lefts = leftLines rows + rights = adjoin2Lines (rightLines rows) right' + +adjoin2 rows@(Row _ right:_) (Row left' right') | Just Break <- maybeLast $ unLine right = Row EmptyLine right' : zipWith Row lefts rights + where lefts = adjoin2Lines (leftLines rows) left' + rights = rightLines rows + +adjoin2 (Row EmptyLine EmptyLine : rows) row = adjoin2 rows row adjoin2 rows (Row left right) = zipWith Row lefts rights where