From fc2a09facce2fe6d06769712ea992f99bf15c8e2 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 29 Dec 2024 19:03:22 +0530 Subject: Make backspace delete a single character in search + split up key input action --- src/Chelleport.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Chelleport.hs') diff --git a/src/Chelleport.hs b/src/Chelleport.hs index d4c21ed..8cc02c7 100644 --- a/src/Chelleport.hs +++ b/src/Chelleport.hs @@ -17,13 +17,14 @@ import qualified SDL run :: Configuration -> IO () run config = do ctx <- initializeContext - -- Cosplaying as elm + -- Cosplaying as elm's state machine runAppWithCtx ctx $ setupAppShell ctx (AppState.initialState config) AppState.update eventHandler View.render where runAppWithCtx :: (MonadIO m) => DrawContext -> AppM m x -> m x runAppWithCtx ctx = (`runReaderT` ctx) . runAppM +-- TODO: Make event handling independent of state eventHandler :: State -> SDL.Event -> Maybe AppAction eventHandler state event = case SDL.eventPayload event of @@ -43,9 +44,9 @@ eventHandler state event = Just $ SetMode $ ModeHints def -- , : Search increment next/prev | checkKey [ctrl, key SDL.KeycodeN, pressed] ev -> - Just $ IncrementHighlightIndex (stateRepetition state) + Just $ IncrementHighlightIndex 1 | checkKey [ctrl, key SDL.KeycodeP, pressed] ev -> - Just $ IncrementHighlightIndex (-1 * stateRepetition state) + Just $ IncrementHighlightIndex (-1) -- : Movement | checkKey [ctrl, hjkl, pressed] ev -> MoveMouseInDirection . hjklDirection <$> toKeyChar (eventToKeycode ev) @@ -56,7 +57,9 @@ eventHandler state event = else Just $ TriggerMouseClick LeftClick -- Backspace: Reset keys | checkKey [key SDL.KeycodeBackspace, pressed] ev -> - Just ResetKeys + case stateMode state of + ModeHints {} -> Just ResetKeys + ModeSearch {} -> Just DeleteLastInput -- : Toggle mouse dragging | checkKey [ctrl, key SDL.KeycodeV, pressed] ev -> Just MouseDragToggle -- cgit v1.3.1