Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added wordBackward

  • Loading branch information...
commit 0afdd787405f2c61b53251c7e8b25a5efa33a5ae 1 parent b2a3e7e
@michaelfeathers authored
Showing with 10 additions and 3 deletions.
  1. +8 −2 editbuffer.hs
  2. +1 −1  todo
  3. +1 −0  vih.hs
View
10 editbuffer.hs
@@ -12,7 +12,7 @@ module EditBuffer
, moveLeft, moveRight, moveUp, moveDown
, moveToHome, moveToEnd, moveToLine
, moveToLineStart, moveToLineEnd
- , wordForward
+ , wordForward, wordBackward
, frame
, showRepresentation
)
@@ -95,6 +95,12 @@ wordForward buffer@(EditBuffer topLine _ contents) =
[] -> buffer
((_,pos) : _) -> EditBuffer topLine (locationFromPosition pos contents) contents
+wordBackward :: EditBuffer -> EditBuffer
+wordBackward buffer@(EditBuffer topLine _ contents) =
+ case dropWord . dropSpaces . reverse . take (absPosition buffer) . numberedElements $ contents of
+ [] -> buffer
+ ((_,pos) : _) -> EditBuffer topLine (locationFromPosition (pos+1) contents) contents
+
frame :: EditBuffer -> EditBuffer
frame buffer@(EditBuffer topLine (x,y) contents)
| y > topLine + 40 = EditBuffer (y - 40) (x,y) contents
@@ -133,7 +139,7 @@ locationFromPosition pos contents =
in (x, y)
isPunct :: Char -> Bool
-isPunct ch = isAscii ch && not (isAlphaNum ch) && not (isControl ch)
+isPunct ch = isAscii ch && not (isAlphaNum ch) && not (isSpace ch) && not (isControl ch)
dropWord :: [(Char,a)] -> [(Char,a)]
dropWord [] = []
View
2  todo
@@ -6,7 +6,7 @@
- Investigate state State T IO monad for mainLoop
x Simplify locationFromPosition. May not need cumulative sum
x Add punct groups as words in wordForward
-- Add wordBackward
+x Add wordBackward
x Write goto line
- Add cw, dw
- Write f, O, a, etc.
View
1  vih.hs
@@ -51,6 +51,7 @@ mainLoop mode previousBuffer =
then mainLoop mode (replaceChar nextCh buffer)
else mainLoop mode buffer
'w' -> mainLoop mode (wordForward buffer)
+ 'b' -> mainLoop mode (wordBackward buffer)
'x' -> mainLoop mode (deleteChar buffer)
_ -> mainLoop mode buffer
Please sign in to comment.
Something went wrong with that request. Please try again.