diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2016-07-24 12:52:30 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2016-07-24 12:52:30 +0200 |
commit | 95eb744c156007d63e285473fd3dd078a79125fc (patch) | |
tree | c90ccae907e964c284f3831c2afd1d8771b09677 /lib | |
parent | 4d68ce63d0eba19bcb29f6da05735ec4ee8f3c15 (diff) | |
download | stylish-haskell-95eb744c156007d63e285473fd3dd078a79125fc.tar.gz |
Fix line patching issue in Editor
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Language/Haskell/Stylish/Editor.hs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Language/Haskell/Stylish/Editor.hs b/lib/Language/Haskell/Stylish/Editor.hs index 24d0a94..cad7e68 100644 --- a/lib/Language/Haskell/Stylish/Editor.hs +++ b/lib/Language/Haskell/Stylish/Editor.hs @@ -19,7 +19,8 @@ module Language.Haskell.Stylish.Editor -------------------------------------------------------------------------------- -import Data.List (intercalate) +import Data.List (intercalate, sortBy) +import Data.Ord (comparing) -------------------------------------------------------------------------------- @@ -41,14 +42,15 @@ moveChange offset (Change block ls) = Change (moveBlock offset block) ls -------------------------------------------------------------------------------- applyChanges :: [Change a] -> [a] -> [a] -applyChanges changes +applyChanges changes0 | overlapping blocks = error $ "Language.Haskell.Stylish.Editor.applyChanges: " ++ "refusing to make overlapping changes on lines " ++ intercalate ", " (map printBlock blocks) - | otherwise = go 1 changes + | otherwise = go 1 changes1 where - blocks = map changeBlock changes + changes1 = sortBy (comparing (blockStart . changeBlock)) changes0 + blocks = map changeBlock changes1 printBlock b = show (blockStart b) ++ "-" ++ show (blockEnd b) |