From c820c4f63c0a147f8371c7a48c62127d00339198 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Sat, 25 Aug 2012 15:23:03 +0700 Subject: [PATCH 1/2] Make incsearch wrap. --- yi/src/library/Yi/Search.hs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/yi/src/library/Yi/Search.hs b/yi/src/library/Yi/Search.hs index b427b7a41..fcd97ea92 100644 --- a/yi/src/library/Yi/Search.hs +++ b/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 From 4172d7c3247f1c0d4a4ce604e12e36eab2947f89 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 11 Sep 2012 00:28:21 +0700 Subject: [PATCH 2/2] Remember search direction of isearch after it finishes successfully. --- yi/src/library/Yi/Search.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yi/src/library/Yi/Search.hs b/yi/src/library/Yi/Search.hs index fcd97ea92..85b0637d7 100644 --- a/yi/src/library/Yi/Search.hs +++ b/yi/src/library/Yi/Search.hs @@ -345,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"