diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-25 00:17:52 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-25 00:32:39 +0530 |
| commit | 82d612b7c37b432bc4abd8e158d6fe076d391ddc (patch) | |
| tree | ef61b3910e5a54fc0ff581e36392e27150ccf470 /src/Chelleport | |
| parent | 459488a2e777380fcb65e3b4dd355fe525ff77ca (diff) | |
| download | chelleport-82d612b7c37b432bc4abd8e158d6fe076d391ddc.tar.gz chelleport-82d612b7c37b432bc4abd8e158d6fe076d391ddc.zip | |
Add <c-n> and <c-p> to walk through matches
Diffstat (limited to 'src/Chelleport')
| -rw-r--r-- | src/Chelleport/Types.hs | 12 | ||||
| -rw-r--r-- | src/Chelleport/Utils.hs | 8 | ||||
| -rw-r--r-- | src/Chelleport/View.hs | 11 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs index 9894e54..43d063f 100644 --- a/src/Chelleport/Types.hs +++ b/src/Chelleport/Types.hs @@ -22,12 +22,19 @@ data Mode | ModeSearch { searchWords :: [OCRMatch], searchFilteredWords :: [OCRMatch], - searchInputText :: String + searchInputText :: String, + searchHighlightedIndex :: Int } deriving (Show, Eq) defaultSearchMode :: Mode -defaultSearchMode = ModeSearch {searchWords = [], searchFilteredWords = [], searchInputText = ""} +defaultSearchMode = + ModeSearch + { searchWords = [], + searchFilteredWords = [], + searchInputText = "", + searchHighlightedIndex = 0 + } defaultHintsMode :: Mode defaultHintsMode = ModeHints @@ -69,6 +76,7 @@ data AppAction | UpdateShiftState Bool | UpdateRepetition Int | SetMode Mode + | IncrementHighlightIndex Int deriving (Show, Eq) data DrawContext = DrawContext diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs index c15a3e8..9423e5d 100644 --- a/src/Chelleport/Utils.hs +++ b/src/Chelleport/Utils.hs @@ -35,3 +35,11 @@ benchmark msg m = do end <- systemNanoseconds <$> liftIO getSystemTime Debug.traceM $ msg ++ " (ms): " ++ show (fromIntegral (end - start) / 1_000_000.0 :: Double) pure result + +itemAt :: [a] -> Int -> Maybe a +itemAt [] _ = Nothing +itemAt (x : _) 0 = Just x +itemAt (_ : xs) i = itemAt xs (i - 1) + +clamp :: (Integral a) => (a, a) -> a -> a +clamp (low, high) n = max low (min high n) diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs index 1a4f1f8..c2e0ff8 100644 --- a/src/Chelleport/View.hs +++ b/src/Chelleport/View.hs @@ -12,13 +12,14 @@ import Foreign.C (CInt) render :: (MonadDraw m) => State -> m () render state = case stateMode state of ModeHints -> renderHintsView state - ModeSearch {searchFilteredWords} -> renderSearchView state searchFilteredWords + ModeSearch {searchFilteredWords, searchHighlightedIndex} -> + renderSearchView state searchFilteredWords searchHighlightedIndex -renderSearchView :: (MonadDraw m) => State -> [OCRMatch] -> m () -renderSearchView state matches = do +renderSearchView :: (MonadDraw m) => State -> [OCRMatch] -> Int -> m () +renderSearchView state matches highlightedIndex = do renderGridLines state - setDrawColor colorWhite - forM_ matches $ \(OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do + forM_ (zip [0 ..] matches) $ \(index, OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do + setDrawColor $ if highlightedIndex == index then colorAccent else colorLightGray fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY) renderHintsView :: (MonadDraw m) => State -> m () |
