diff options
-rw-r--r-- | design/design.css | 2 | ||||
-rw-r--r-- | index.html | 7 | ||||
-rw-r--r-- | src/Main.elm | 5 | ||||
-rw-r--r-- | src/Model/Edition/TimeEdition.elm | 16 |
4 files changed, 15 insertions, 15 deletions
diff --git a/design/design.css b/design/design.css index 11002aa..09ad82b 100644 --- a/design/design.css +++ b/design/design.css @@ -113,7 +113,7 @@ .timer > button.name { width: 300px; - border-radius: 0px; + cursor: text; } .timer > .time { @@ -18,7 +18,8 @@ <script> var timer = Elm.fullscreen(Elm.Main, { initialTime: new Date().getTime(), - clickAway: [] + clickAway: [], + keyPress: 0 }); timer.ports.clickPosition.subscribe(function(pos) { @@ -45,6 +46,10 @@ } }); + document.onkeypress = function(event) { + timer.ports.keyPress.send(event.which); + }; + </script> </html> diff --git a/src/Main.elm b/src/Main.elm index 4fab1e9..fda7c01 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -11,6 +11,7 @@ import Keyboard import Char import Dict import List +import Keyboard (KeyCode) import Model.Model (..) import Model.Position (..) @@ -31,7 +32,7 @@ input = [ Signal.subscribe updates , Signal.map DeltaTime (fps 30) , Signal.map (\_ -> ClickAway) clickAway - , Signal.map KeyPressed Keyboard.lastPressed + , Signal.map KeyPressed keyPress ] port clickPosition : Signal Value @@ -52,6 +53,8 @@ port ringingTimers = model |> Signal.dropRepeats +port keyPress : Signal KeyCode + port clickAway : Signal () port initialTime : Time diff --git a/src/Model/Edition/TimeEdition.elm b/src/Model/Edition/TimeEdition.elm index 6999b25..2ba1628 100644 --- a/src/Model/Edition/TimeEdition.elm +++ b/src/Model/Edition/TimeEdition.elm @@ -9,24 +9,16 @@ import List import Array import String import Keyboard (KeyCode) +import Char import Utils.List (..) import Utils.Maybe (..) keyCodeToChar : KeyCode -> Maybe Char keyCodeToChar 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 - |> Array.get (code - zero) + let char = Char.fromCode code + in if Char.isDigit char + then Just char else Nothing toTime : List Char -> Time |