aboutsummaryrefslogtreecommitdiff
path: root/src/Model/TimerEdition.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-21 12:50:45 +0100
committerJoris Guyonvarch2015-03-21 12:50:45 +0100
commita01687a3f0479734882eabed82bd100fc811b698 (patch)
tree7d764652bb57bb8983cf737fb3ab8ec6a9f59ec1 /src/Model/TimerEdition.elm
parent29eac851219e36bccf2724b05d52b70438b5bf3f (diff)
Number from the top row are accepted too
Diffstat (limited to 'src/Model/TimerEdition.elm')
-rw-r--r--src/Model/TimerEdition.elm17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Model/TimerEdition.elm b/src/Model/TimerEdition.elm
index 5feea33..2ec98b7 100644
--- a/src/Model/TimerEdition.elm
+++ b/src/Model/TimerEdition.elm
@@ -2,7 +2,7 @@ module Model.TimerEdition
( TimerEdition
, Numbers
, newTimerEdition
- , keyCodeToChar
+ , keyCodeToNumberChar
, toTime
, toMinutesAndSeconds
) where
@@ -16,6 +16,7 @@ import Keyboard (KeyCode)
import Model.Id (..)
import Utils.List (..)
+import Utils.Maybe (..)
type alias TimerEdition =
{ id : Id
@@ -29,10 +30,16 @@ newTimerEdition id =
, numbers = []
}
-keyCodeToChar : KeyCode -> Maybe Char
-keyCodeToChar code =
- let zero = 96
- nine = zero + 9
+keyCodeToNumberChar : KeyCode -> Maybe Char
+keyCodeToNumberChar code =
+ List.map (flip keyCodeToCharFromZero code) zeroKeyCodes
+ |> List.foldl orElse Nothing
+
+zeroKeyCodes = [48, 96]
+
+keyCodeToCharFromZero : KeyCode -> KeyCode -> Maybe Char
+keyCodeToCharFromZero zero code =
+ let nine = zero + 9
in if code >= zero && code <= nine
then ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|> Array.fromList