Skip to content

Commit aa4a494

Browse files
Fix search direction logic bug.
1 parent ed6ff61 commit aa4a494

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

Core.hs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,8 @@ jumpToDir fn = modifyHS_ $ \st -> if size st == 0 then st else
453453

454454
------------------------------------------------------------------------
455455

456-
--
457456
-- a bit of bounded parametric polymorphism so we can abstract over record selectors
458457
-- in the regex search stuff below
459-
--
460458
class Lookup a where extract :: a -> RawFilePath
461459
instance Lookup Dir where extract = takeFileName . dname
462460
instance Lookup File where extract = fbase
@@ -479,25 +477,20 @@ genericJumpToMatch :: Lookup a
479477
-> (HState -> (Array Int a, Int, Int))
480478
-> (Int -> HState -> Int)
481479
-> IO ()
482-
483480
genericJumpToMatch re sw k sel = do
484-
found <- modifyHS $ \st -> do
485-
let mre = case re of
486-
Nothing -> case regex st of
487-
Nothing -> Nothing
488-
Just (r, d) -> Just (r, d==sw)
489-
Just s -> case compileM (P.pack s) [caseless, utf8] of
490-
Left _ -> Nothing
491-
Right v -> Just (v, sw)
492-
flip (maybe (st, False)) mre \ (p, forwards) -> do
481+
found <- modifyHS \st -> let
482+
mre = case re of
483+
Nothing -> (\(r, d) -> (st, r, d == sw)) <$> regex st
484+
Just s -> case compileM (P.pack s) [caseless, utf8] of
485+
Left _ -> Nothing
486+
Right v -> Just (st { regex = Just (v, sw) }, v, sw)
487+
in flip (maybe (st, False)) mre \(st', p, forwards) -> do
493488
let (fs, cur, m) = k st
494489
l = if forwards then [cur+1..m-1] ++ [0..cur]
495490
else [cur-1,cur-2..0] ++ [m-1,m-2..cur]
496-
st' = st { regex = Just (p, forwards==sw) }
497491
case [ i | i <- l, isJust $ match p (extract (fs ! i)) [] ] of
498492
i:_ -> (st' { cursor = sel i st }, True)
499493
_ -> (st', False)
500-
501494
unless found $ putMessage $ Fast "No match found." defaultSty
502495

503496
------------------------------------------------------------------------

0 commit comments

Comments
 (0)