Create a new tile on pressing Enter
This commit is contained in:
parent
d3fd2f68c8
commit
9e2bd85175
14
src/Main.elm
14
src/Main.elm
|
@ -15,6 +15,7 @@ import Html.Attributes exposing (class, disabled, id, style, value)
|
|||
import Html.Attributes.Extra as Attributes exposing (attributeIf)
|
||||
import Html.Extra exposing (viewMaybe)
|
||||
import Html.Events exposing (onBlur, onClick, onInput, onMouseDown, onMouseEnter, onMouseLeave)
|
||||
import Html.Events.Extra exposing (onEnter)
|
||||
import Html.Lazy exposing (lazy, lazy2)
|
||||
import Json.Decode as D
|
||||
import List exposing (map, singleton)
|
||||
|
@ -41,7 +42,7 @@ type Msg
|
|||
| Click Int Int Int Int
|
||||
| SetTileText Int Int String
|
||||
| AddTile Int
|
||||
| TileDeselected Int
|
||||
| PruneTile Int Int
|
||||
| HeldOverNewTile Int Int
|
||||
| NewMousePos Int Int
|
||||
| StartDrag Int Int Tile Int Int
|
||||
|
@ -182,8 +183,9 @@ viewTile isTileHeld columnIndex tileIndex tile =
|
|||
, input
|
||||
[ value tile.text
|
||||
, onInput (SetTileText columnIndex tileIndex)
|
||||
, onBlur (TileDeselected columnIndex)
|
||||
, attributeIf (isBlank tile.text) <| onBlur (PruneTile columnIndex tileIndex)
|
||||
, attributeIf (isBlank tile.text) (id "new-tile")
|
||||
, onEnter (AddTile columnIndex)
|
||||
]
|
||||
[]
|
||||
, svg
|
||||
|
@ -260,10 +262,6 @@ addTileToColumn column =
|
|||
isTileEmpty : Tile -> Bool
|
||||
isTileEmpty = .text >> isEmpty
|
||||
|
||||
pruneTiles : Column -> Column
|
||||
pruneTiles column =
|
||||
{ column | tiles = Array.filter (not << isTileEmpty) column.tiles }
|
||||
|
||||
updateTileText : String -> Tile -> Tile
|
||||
updateTileText text tile =
|
||||
{ tile | text = text }
|
||||
|
@ -321,9 +319,9 @@ update msg model = case Debug.log "UPDATE" msg of
|
|||
addTileToColumn
|
||||
model
|
||||
|> withCmd (Task.attempt (constant Noop) (focus "new-tile"))
|
||||
TileDeselected columnIndex ->
|
||||
PruneTile columnIndex tileIndex ->
|
||||
modColumnInPage columnIndex
|
||||
pruneTiles
|
||||
(removeTileFromColumn tileIndex)
|
||||
model
|
||||
|> withoutCmd
|
||||
HeldOverNewTile columnIndex tileIndex -> case model.heldTile of
|
||||
|
|
Loading…
Reference in New Issue