Skip to content
Browse files

Rewrote locationFromPosition

  • Loading branch information...
1 parent 3467978 commit 7df55827ae33225ec74ac9283ad5cdcf1f0013c0 @michaelfeathers committed
Showing with 8 additions and 8 deletions.
  1. +7 −7 editbuffer.hs
  2. +1 −1 todo
View
14 editbuffer.hs
@@ -93,7 +93,7 @@ wordForward :: EditBuffer -> EditBuffer
wordForward buffer@(EditBuffer topLine _ contents) =
case dropWhile (\(x,_) -> isSpace x) . dropWhile (\(x,_) -> isAlphaNum x) . dropWhile (\(_,pos) -> pos < absPosition buffer) . numberedElements $ contents of
[] -> buffer
- ((_,pos) : _) -> EditBuffer topLine (locationFromPosition pos buffer) contents
+ ((_,pos) : _) -> EditBuffer topLine (locationFromPosition pos contents) contents
frame :: EditBuffer -> EditBuffer
frame buffer@(EditBuffer topLine (x,y) contents)
@@ -125,12 +125,12 @@ absPosition :: EditBuffer -> Int
absPosition (EditBuffer _ (x, y) contents) =
(x+) . length . unlines . take y . lines $ contents
-locationFromPosition :: Int -> EditBuffer -> Location
-locationFromPosition pos (EditBuffer _ _ contents) =
- let wayPoints = takeWhile (<= pos) . scanl1 (+) . map ((+1).length) . lines $ contents
- in case wayPoints of
- [] -> (pos, 0)
- xs -> (pos - (last xs), length wayPoints)
+locationFromPosition :: Int -> String -> Location
+locationFromPosition pos contents =
+ let foreText = init . lines . take (pos + 1) $ contents
+ x = pos - (length $ unlines foreText)
+ y = length foreText
+ in (x, y)
saturate :: (Int,Int) -> EditBuffer -> EditBuffer
saturate (adjX,adjY) = satX adjX . satY adjY
View
2 todo
@@ -4,7 +4,7 @@
- Put test driver in place
- Documentation
- Investigate state State T IO monad for mainLoop
-- Simplify locationFromPosition. May not need cumulative sum
+x Simplify locationFromPosition. May not need cumulative sum
- Add punct groups as words in wordForward
- Add wordBackward
x Write goto line

0 comments on commit 7df5582

Please sign in to comment.
Something went wrong with that request. Please try again.