diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-28 14:53:58 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-28 14:53:58 +0530 |
| commit | 568923344f0941b2771459dd8dbe935ac971a968 (patch) | |
| tree | 54a07e8a3c25c85b299fe9d9273620972f03b508 | |
| parent | b8c389eac5f875fc7ae9a5ab9ac446d24a079448 (diff) | |
| download | chelleport-568923344f0941b2771459dd8dbe935ac971a968.tar.gz chelleport-568923344f0941b2771459dd8dbe935ac971a968.zip | |
Allow clicking with enter
Diffstat (limited to '')
| -rw-r--r-- | specs/Specs/AppEventSpec.hs | 18 | ||||
| -rw-r--r-- | specs/Specs/AppStateSpec.hs | 2 | ||||
| -rw-r--r-- | specs/Specs/ViewSpec.hs | 3 | ||||
| -rw-r--r-- | src/Chelleport.hs | 4 | ||||
| -rw-r--r-- | src/Chelleport/AppState.hs | 3 | ||||
| -rw-r--r-- | src/Chelleport/Types.hs | 24 |
6 files changed, 36 insertions, 18 deletions
diff --git a/specs/Specs/AppEventSpec.hs b/specs/Specs/AppEventSpec.hs index e643958..98509de 100644 --- a/specs/Specs/AppEventSpec.hs +++ b/specs/Specs/AppEventSpec.hs @@ -2,6 +2,7 @@ module Specs.AppEventSpec where import Chelleport (eventHandler) import Chelleport.Types +import Data.Default (Default (def)) import qualified SDL import SDL.Internal.Numbered (FromNumber (fromNumber)) import Test.Hspec @@ -26,7 +27,7 @@ test = do SDL.keyboardEventKeyMotion = motion } let defaultMod = fromNumber 0 - let currentState = defaultAppState + let currentState = def context "when window quit event is triggered" $ do it "shuts down app" $ do @@ -58,6 +59,21 @@ test = do let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeSpace SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) action `shouldBe` Just (ChainMouseClick LeftClick) + context "when enter key is pressed" $ do + it "triggers left mouse button click" $ do + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeReturn SDL.Pressed defaultMod + action `shouldBe` Just (TriggerMouseClick LeftClick) + + context "when pressed with right shift" $ do + it "chains left mouse button click" $ do + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeReturn SDL.Pressed (defaultMod {SDL.keyModifierRightShift = True}) + action `shouldBe` Just (ChainMouseClick LeftClick) + + context "when pressed with left shift" $ do + it "chains left mouse button click" $ do + let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeReturn SDL.Pressed (defaultMod {SDL.keyModifierLeftShift = True}) + action `shouldBe` Just (ChainMouseClick LeftClick) + context "when minus key is pressed" $ do it "triggers left mouse button click" $ do let action = eventHandler currentState $ mkKeyboardEvent SDL.KeycodeMinus SDL.Pressed defaultMod diff --git a/specs/Specs/AppStateSpec.hs b/specs/Specs/AppStateSpec.hs index 44da414..d69ab0e 100644 --- a/specs/Specs/AppStateSpec.hs +++ b/specs/Specs/AppStateSpec.hs @@ -39,7 +39,7 @@ test = do action `shouldBe` Just (SetMode defaultSearchMode) describe "#update" $ do - let defaultState = defaultAppState {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]} + let defaultState = def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]} context "with action ChainMouseClick" $ do context "when repetition is 1" $ do diff --git a/specs/Specs/ViewSpec.hs b/specs/Specs/ViewSpec.hs index 79c8173..f3cfdf2 100644 --- a/specs/Specs/ViewSpec.hs +++ b/specs/Specs/ViewSpec.hs @@ -3,12 +3,13 @@ module Specs.ViewSpec where import Chelleport.Config import Chelleport.Types import Chelleport.View +import Data.Default (Default (def)) import Test.Hspec import TestUtils test :: SpecWith () test = do - let defaultState = defaultAppState {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]} + let defaultState = def {stateGrid = [["ABC", "DEF"], ["DJK", "JKL"]]} describe "#render" $ do context "when key sequence is empty" $ do diff --git a/src/Chelleport.hs b/src/Chelleport.hs index 029821e..370951e 100644 --- a/src/Chelleport.hs +++ b/src/Chelleport.hs @@ -45,8 +45,8 @@ eventHandler state event = -- <C-hjkl>: Movement | checkKey [ctrl, hjkl, pressed] ev -> MoveMouseInDirection . hjklDirection <$> toKeyChar (eventToKeycode ev) - -- Space / Shift+Space : Left click/chain left click - | checkKey [key SDL.KeycodeSpace, pressed] ev -> + -- Space / Enter / Shift+Space / Shift+Enter : Left click/chain left click + | checkKey [key SDL.KeycodeSpace <||> key SDL.KeycodeReturn, pressed] ev -> if shift ev then Just $ ChainMouseClick LeftClick else Just $ TriggerMouseClick LeftClick diff --git a/src/Chelleport/AppState.hs b/src/Chelleport/AppState.hs index 4c8e0a8..fe397e8 100644 --- a/src/Chelleport/AppState.hs +++ b/src/Chelleport/AppState.hs @@ -9,6 +9,7 @@ import Chelleport.Types import Chelleport.Utils (cIntToInt, clamp, intToCInt, isEmpty, itemAt) import Control.Monad (replicateM_) import Data.Char (toLower) +import Data.Default (Default (def)) import Data.Maybe (isJust) import qualified Text.Fuzzy as Fuzzy @@ -16,7 +17,7 @@ initialState :: (Monad m) => Configuration -> m (State, Maybe AppAction) initialState config = do let cells = either error id $ generateGrid 0 (rows, columns) hintKeys let action = Just $ SetMode $ configMode config - pure (defaultAppState {stateGrid = cells}, action) + pure (def {stateGrid = cells}, action) where rows = 9 columns = 16 diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs index cc1a4c3..3deb4a8 100644 --- a/src/Chelleport/Types.hs +++ b/src/Chelleport/Types.hs @@ -52,18 +52,18 @@ data State = State } deriving (Show, Eq) -defaultAppState :: State -defaultAppState = - State - { stateGrid = [], - stateKeySequence = "", - stateIsMatched = False, - stateIsShiftPressed = False, - stateIsDragging = False, - stateRepetition = 1, - stateIsModeInitialized = False, - stateMode = ModeHints - } +instance Default State where + def = + State + { stateGrid = [], + stateKeySequence = "", + stateIsMatched = False, + stateIsShiftPressed = False, + stateIsDragging = False, + stateRepetition = 1, + stateIsModeInitialized = False, + stateMode = ModeHints + } data Direction = DirUp | DirDown | DirLeft | DirRight deriving (Show, Eq) |
