diff options
author | defanor <defanor@uberspace.net> | 2017-12-22 00:55:52 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-12-22 00:55:52 +0300 |
commit | 9d7940ac07b1e1bf408d39df05305ef879f27729 (patch) | |
tree | 9887c4c4382cc75163a20ce0524ca1d5b83f4162 /Pancake.hs | |
parent | 0d6038c53bd671505b8bdbc3f33f5479351ac6e6 (diff) |
Use a list of elements instead of enumeration
The list is ordered anyway, no need to keep numbers there.
Diffstat (limited to 'Pancake.hs')
-rw-r--r-- | Pancake.hs | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -188,18 +188,18 @@ goTo t u' = do in s {history = (take (historyDepth $ conf s) $ HE uri doc 0:prev, [])} -- | Line number to block position. -lineToPos :: [(Int, Int, Int)] -> Int -> Int +lineToPos :: [(Int, Int)] -> Int -> Int lineToPos bs n = - case filter (\(_, f, l) -> f <= n && n < l) bs of + case filter (\(_, (f, l)) -> f <= n && n < l) (zip [0..] bs) of [] -> 0 - xs -> (\(p, _, _) -> p) $ - maximumBy (\(_, l, _) (_, l', _) -> compare l l') xs + xs -> (\(p, _) -> p) $ + maximumBy (\(_, (l, _)) (_, (l', _)) -> compare l l') xs -- | Block position to line number. -posToLine :: [(Int, Int, Int)] -> Int -> Int -posToLine bs p = case filter (\(p', _, _) -> p' == p) bs of - [] -> 1 - ((_, f, _):_) -> f +posToLine :: [(Int, Int)] -> Int -> Int +posToLine bs p + | length bs <= p = 1 + | otherwise = fst $ bs !! p -- | Scrolls to a line, which would be at the bottom for CLI. scrollToLine :: MonadIO m => Int -> StateT LoopState m () |