Permalink
Browse files

Made wordForward advance through punct groups

  • Loading branch information...
1 parent 7df5582 commit b2a3e7ed79550299ff6de46fb8580ff953b71d78 @michaelfeathers committed Aug 16, 2009
Showing with 20 additions and 2 deletions.
  1. +19 −1 editbuffer.hs
  2. +1 −1 todo
View
@@ -91,7 +91,7 @@ moveToLineEnd buffer@(EditBuffer topLine (_,y) contents) =
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
+ case dropSpaces . dropWord . drop (absPosition buffer) . numberedElements $ contents of
[] -> buffer
((_,pos) : _) -> EditBuffer topLine (locationFromPosition pos contents) contents
@@ -132,6 +132,24 @@ locationFromPosition pos contents =
y = length foreText
in (x, y)
+isPunct :: Char -> Bool
+isPunct ch = isAscii ch && not (isAlphaNum ch) && not (isControl ch)
+
+dropWord :: [(Char,a)] -> [(Char,a)]
+dropWord [] = []
+dropWord all@((ch,_):xs)
+ | isPunct ch = dropPuncts all
+ | isAlphaNum ch = dropAlphaNums all
+ | otherwise = all
+
+dropPuncts, dropSpaces, dropAlphaNums :: [(Char,a)] -> [(Char,a)]
+dropPuncts = dropInNumbered isPunct
+dropSpaces = dropInNumbered isSpace
+dropAlphaNums = dropInNumbered isAlphaNum
+
+dropInNumbered :: (Char -> Bool) -> [(Char,a)] -> [(Char,a)]
+dropInNumbered f = dropWhile (\(ch,_) -> f ch)
+
saturate :: (Int,Int) -> EditBuffer -> EditBuffer
saturate (adjX,adjY) = satX adjX . satY adjY
View
@@ -5,7 +5,7 @@
- Documentation
- Investigate state State T IO monad for mainLoop
x Simplify locationFromPosition. May not need cumulative sum
-- Add punct groups as words in wordForward
+x Add punct groups as words in wordForward
- Add wordBackward
x Write goto line
- Add cw, dw

0 comments on commit b2a3e7e

Please sign in to comment.