diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-14 13:04:36 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-14 13:04:36 +0530 |
| commit | 9368c616e202fc67c15d6128a2110d05998f4290 (patch) | |
| tree | ba30236841d12e24e9b8b84b42579d2148c1445d /src/Chelleport/KeySequence.hs | |
| parent | 7ab99bd80e30d0cc2cf21e4cda47870821b8fd47 (diff) | |
| download | chelleport-9368c616e202fc67c15d6128a2110d05998f4290.tar.gz chelleport-9368c616e202fc67c15d6128a2110d05998f4290.zip | |
Move the mouse to the cell position after key sequence match
Diffstat (limited to '')
| -rw-r--r-- | src/Chelleport/KeySequence.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Chelleport/KeySequence.hs b/src/Chelleport/KeySequence.hs index 88658f1..1046a98 100644 --- a/src/Chelleport/KeySequence.hs +++ b/src/Chelleport/KeySequence.hs @@ -2,8 +2,15 @@ module Chelleport.KeySequence where import Data.List (isPrefixOf, nub) import qualified Data.Map as Map +import Data.Maybe (isJust) import qualified SDL +-- padded :: Int -> a -> [a] -> [a] +-- padded 0 _ ls = ls +-- padded n x ls +-- | length ls > n = ls +-- | otherwise = padded (n - 1) x (ls ++ [x]) + safeHead :: a -> [a] -> a safeHead def [] = def safeHead _ (x : _) = x @@ -17,6 +24,19 @@ nextChars keys cells = matches = concatMap (filter (isPrefixOf keys)) cells result = concatMap (take 1 . drop (length keys)) matches +findMatchPosition :: [Char] -> [[[Char]]] -> Maybe (Int, Int) +findMatchPosition keys = findWithIndex findMatch 0 + where + findMatch row = + fst <$> findWithIndex (\c -> if c == keys then Just () else Nothing) 0 row + + findWithIndex :: (x -> Maybe r) -> Int -> [x] -> Maybe (Int, r) + findWithIndex _pred _index [] = Nothing + findWithIndex predicate index (x : ls) = + case predicate x of + Just item -> Just (index, item) + Nothing -> findWithIndex predicate (index + 1) ls + isValidKey :: SDL.Keycode -> Bool isValidKey key = Map.member key keycodeMapping |
