aboutsummaryrefslogtreecommitdiff
path: root/src/Update/UpdateEdition.elm
blob: d94bd1e323af7a52d897b845c55a86f1533f47c6 (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
31
32
33
module Update.UpdateEdition
  ( updateEdition
  , EditionAction(..)
  ) where

import Char
import Char (KeyCode)

import Model.Edition.Edition (..)

import Utils.List (..)

type EditionAction =
  DeleteLast
  | AddChar KeyCode

updateEdition : EditionAction -> Edition -> Edition
updateEdition action edition =
  case action of
    DeleteLast ->
      case maybeTail edition.chars of
        Just tailChars ->
          { edition | chars <- tailChars }
        Nothing ->
          edition
    AddChar keyCode ->
      case keyCodeToChar edition.kind keyCode of
        Just char ->
          if keyCode == 32 && maybeHead edition.chars == Just (Char.fromCode 32)
            then edition
            else { edition | chars <- char :: edition.chars }
        Nothing ->
          edition