Skip to content

Commit

Permalink
Merge pull request #41 from ethercrow/incsearch
Browse files Browse the repository at this point in the history
Some Incremental search improvements
  • Loading branch information
ethercrow committed Sep 16, 2012
2 parents 1a52ed8 + 4172d7c commit 9d5854d
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions yi/src/library/Yi/Search.hs
Expand Up @@ -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
Expand Down Expand Up @@ -334,9 +345,10 @@ iSearch = "isearch"
isearchEnd :: Bool -> EditorM ()
isearchEnd accept = do
Isearch s <- getDynamic
let (lastSearched,_,_) = head s
let (lastSearched,_,dir) = head s
let (_,p0,_) = last s
historyFinishGen iSearch (return lastSearched)
putA searchDirectionA dir
if accept
then do withBuffer0 $ setSelectionMarkPointB $ regionStart p0
printMsg "Quit"
Expand Down

0 comments on commit 9d5854d

Please sign in to comment.