diff options
Diffstat (limited to 'lib/Daffm/Event.hs')
| -rw-r--r-- | lib/Daffm/Event.hs | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/lib/Daffm/Event.hs b/lib/Daffm/Event.hs index 262686b..04f687b 100644 --- a/lib/Daffm/Event.hs +++ b/lib/Daffm/Event.hs @@ -3,13 +3,12 @@ module Daffm.Event where import qualified Brick.Types as T import qualified Brick.Widgets.Edit as Editor import qualified Brick.Widgets.List as L -import Control.Monad.State (get, gets, modify) +import Control.Monad.State (gets, modify) import Daffm.Action.Cmdline import Daffm.Action.Commands +import Daffm.Action.Keymap (appendToKeySequence, processKeySequence) import Daffm.State (cacheDirPosition) -import Daffm.Types (AppEvent, AppState (..), Command (..), FocusTarget (..), Key, KeyMatchResult (..), KeySequence, Keymap) -import qualified Data.Map as Map -import Data.Maybe (fromMaybe) +import Daffm.Types (AppEvent, AppState (..), FocusTarget (..), KeyMatchResult (..)) import qualified Graphics.Vty as V appEvent :: T.BrickEvent FocusTarget e -> AppEvent () @@ -36,33 +35,3 @@ appEvent brickevent@(T.VtyEvent event) = do modify (\appState -> appState {stateFiles = newFiles}) modify cacheDirPosition appEvent _ = pure () - -matchKeySequence :: Keymap -> KeySequence -> KeyMatchResult -matchKeySequence keymaps keys - | Map.member keys keymaps = - MatchSuccess . fromMaybe CmdNoop $ Map.lookup keys keymaps - | otherwise = partial keymaps keys - where - partial _ [] = MatchFailure - partial (Map.null -> True) _ = MatchFailure - partial keymaps' keys' = if hasMatch then MatchPartial else MatchFailure - where - hasMatch = any (startsWith keys' . fst) (Map.toList keymaps') - startsWith ls1 ls2 = ls1 == take (length ls1) ls2 - -processKeySequence :: AppEvent KeyMatchResult -processKeySequence = do - (AppState {stateKeyMap, stateKeySequence}) <- get - let match = matchKeySequence stateKeyMap stateKeySequence - case match of - MatchSuccess cmd -> do - processCommand cmd - modify (\st -> st {stateKeySequence = []}) - MatchPartial -> pure () - MatchFailure -> do - modify (\st -> st {stateKeySequence = []}) - pure match - -appendToKeySequence :: Key -> AppEvent () -appendToKeySequence key = - modify (\st -> st {stateKeySequence = stateKeySequence st <> [key]}) |
