diff options
author | Joris Guyonvarch | 2015-03-22 17:13:04 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-22 17:13:04 +0100 |
commit | b3076f37700291221ededbaf996a065b006cf42d (patch) | |
tree | 26535eb8756329565529f2c5383701aa41c06c17 /src | |
parent | e7237e9f2a01197890d85b6ecc223e4022630cb8 (diff) |
Do not add more than one space when editing name
Diffstat (limited to 'src')
-rw-r--r-- | src/Model/Edition/Edition.elm | 10 | ||||
-rw-r--r-- | src/Model/Edition/NameEdition.elm | 5 | ||||
-rw-r--r-- | src/Update/Update.elm | 2 | ||||
-rw-r--r-- | src/Update/UpdateEdition.elm | 7 | ||||
-rw-r--r-- | src/Utils/List.elm | 7 | ||||
-rw-r--r-- | src/View/Timer.elm | 32 |
6 files changed, 43 insertions, 20 deletions
diff --git a/src/Model/Edition/Edition.elm b/src/Model/Edition/Edition.elm index 89a0b52..be7aa02 100644 --- a/src/Model/Edition/Edition.elm +++ b/src/Model/Edition/Edition.elm @@ -3,9 +3,11 @@ module Model.Edition.Edition , Kind(..) , newEdition , keyCodeToChar + , isEmpty ) where import Keyboard (KeyCode) +import String import Model.Id (..) import Model.Edition.NameEdition as NameEdition @@ -32,3 +34,11 @@ keyCodeToChar kind = case kind of Name -> NameEdition.keyCodeToChar Time -> TimeEdition.keyCodeToChar + +isEmpty : Edition -> Bool +isEmpty edition = + edition.chars + |> String.fromList + |> String.trim + |> String.length + |> (==) 0 diff --git a/src/Model/Edition/NameEdition.elm b/src/Model/Edition/NameEdition.elm index 18224ea..89e5441 100644 --- a/src/Model/Edition/NameEdition.elm +++ b/src/Model/Edition/NameEdition.elm @@ -12,4 +12,7 @@ keyCodeToChar : KeyCode -> Maybe Char keyCodeToChar = Just << Char.fromCode renderNameEdition : List Char -> String -renderNameEdition = String.fromList << List.reverse +renderNameEdition chars = + chars + |> List.reverse + |> String.fromList diff --git a/src/Update/Update.elm b/src/Update/Update.elm index 5a902df..a556e36 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -105,7 +105,7 @@ validEdition : Model -> Model validEdition model = case model.edition of Just edition -> - if List.isEmpty edition.chars + if isEmpty edition then model else diff --git a/src/Update/UpdateEdition.elm b/src/Update/UpdateEdition.elm index 911a4c1..d94bd1e 100644 --- a/src/Update/UpdateEdition.elm +++ b/src/Update/UpdateEdition.elm @@ -3,7 +3,8 @@ module Update.UpdateEdition , EditionAction(..) ) where -import Char (..) +import Char +import Char (KeyCode) import Model.Edition.Edition (..) @@ -25,6 +26,8 @@ updateEdition action edition = AddChar keyCode -> case keyCodeToChar edition.kind keyCode of Just char -> - { edition | chars <- char :: edition.chars } + if keyCode == 32 && maybeHead edition.chars == Just (Char.fromCode 32) + then edition + else { edition | chars <- char :: edition.chars } Nothing -> edition diff --git a/src/Utils/List.elm b/src/Utils/List.elm index 64ebaa5..83b11eb 100644 --- a/src/Utils/List.elm +++ b/src/Utils/List.elm @@ -1,6 +1,7 @@ module Utils.List ( repeat , splitAt + , maybeHead , maybeTail ) where @@ -17,6 +18,12 @@ repeat count elem = splitAt : Int -> List a -> (List a, List a) splitAt n xs = (List.take n xs, List.drop n xs) +maybeHead : List a -> Maybe a +maybeHead xs = + case xs of + x :: _ -> Just x + _ -> Nothing + maybeTail : List a -> Maybe (List a) maybeTail xs = case xs of diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 50144ef..a88f9dd 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -49,17 +49,18 @@ nameBlockEdition : Id -> Timer -> Edition -> Html nameBlockEdition id timer edition = div [ [ (True, "name block edition") - , (List.isEmpty edition.chars, "empty") + , (isEmpty edition, "empty") ] |> activatedClasses , onClick (Signal.send updates NoOp) ] - [ if List.isEmpty edition.chars + [ if isEmpty edition then text (timerName id timer) else edition.chars |> renderNameEdition + |> flip String.append "_" |> text ] @@ -83,20 +84,19 @@ timeBlockReadOnly id timer = timeBlockEdition : Timer -> Edition -> Html timeBlockEdition timer edition = - let isEmptyEdition = List.isEmpty edition.chars - in div - [ [ (True, "time block edition") - , (isEmptyEdition, "empty") - ] - |> activatedClasses - , onClick (Signal.send updates NoOp) - ] - [ if isEmptyEdition - then - timeWithProgressBar timer - else - text (editionView edition.chars) - ] + div + [ [ (True, "time block edition") + , (isEmpty edition, "empty") + ] + |> activatedClasses + , onClick (Signal.send updates NoOp) + ] + [ if isEmpty edition + then + timeWithProgressBar timer + else + text (editionView edition.chars) + ] editionView : List Char -> String editionView numbers = |