Browse files

Make incsearch wrap.

  • Loading branch information...
1 parent bf5b459 commit c820c4f63c0a147f8371c7a48c62127d00339198 @ethercrow ethercrow committed Aug 25, 2012
Showing with 20 additions and 9 deletions.
  1. +20 −9 yi/src/library/Yi/Search.hs
View
29 yi/src/library/Yi/Search.hs
@@ -244,19 +244,30 @@ isearchFunE fun = do
printMsg $ "I-search: " ++ current
setRegexE srch
prevPoint <- withBuffer0 pointB
- mp <- withBuffer0 $ do
+ matches <- withBuffer0 $ do
moveTo $ regionStart p0
when (direction == Backward) $
moveN $ length current
regexB direction srch
- case mp of
- [] -> do withBuffer0 $ moveTo prevPoint -- go back to where we were
- setDynamic $ Isearch ((current,p0,direction):s)
- printMsg $ "Failing I-search: " ++ current
- (p:_) -> do
- withBuffer0 $ do
- moveTo (regionEnd p)
- setDynamic $ Isearch ((current,p,direction):s)
+
+ let onSuccess p = do withBuffer0 $ moveTo (regionEnd p)
+ setDynamic $ Isearch ((current,p,direction):s)
+
+ case matches of
+ (p:_) -> onSuccess p
+ [] -> do matchesAfterWrap <- withBuffer0 $ do
+ case direction of
+ Forward -> moveTo 0
+ Backward -> do
+ bufferLength <- sizeB
+ moveTo bufferLength
+ regexB direction srch
+
+ case matchesAfterWrap of
+ (p:_) -> onSuccess p
+ [] -> do withBuffer0 $ moveTo prevPoint -- go back to where we were
+ setDynamic $ Isearch ((current,p0,direction):s)
+ printMsg $ "Failing I-search: " ++ current
isearchDelE :: EditorM ()
isearchDelE = do

0 comments on commit c820c4f

Please sign in to comment.