aboutsummaryrefslogtreecommitdiff
path: root/src/Edition/Update.elm
blob: e219629383abce86addd5cc3e39c57dcd30f4ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Edition.Update exposing
  ( updateEdition
  )

import Char
import Char exposing (KeyCode)
import List

import Edition.Model exposing (..)
import Edition.Msg exposing (..)

updateEdition : Msg -> Edition -> Edition
updateEdition msg edition =
  case msg of

    DeleteLast ->
      case List.tail edition.chars of
        Just tailChars ->
          { edition | chars = tailChars }
        Nothing ->
          edition

    AddChar keyCode ->
      case keyCodeToChar edition.kind keyCode of
        Just char ->
          if keyCode == 32 && List.head edition.chars == Just (Char.fromCode 32)
            then edition
            else { edition | chars = char :: edition.chars }
        Nothing ->
          edition