<commit_before>module LearnA exposing (main)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (on, onInput)
import Json.Decode as JD
import Events exposing (onEnter)

type Msg
    = AddTag
    | NewTagInput String


type alias Model =
    { tags : List String
    , newTag : String
    }


onDown : (String -> Int -> Msg) -> Attribute Msg
onDown tagger =
    on "keydown"
        (JD.map2
            (\s i -> tagger s i)
            (JD.at [ "target", "value" ] JD.string)
            (JD.field "keyCode" JD.int)
        )


update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
    case message of
        AddTag ->
            ( { model
                | tags = List.append model.tags [ model.newTag ]
                , newTag = ""
              }
            , Cmd.none
            )

        NewTagInput newTag ->
            ( { model | newTag = newTag }, Cmd.none )


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.none


tagView tag =
    p [] [ text tag ]


view : Model -> Html Msg
view model =
    div []
        [ h1 [] [ text "Learn Elm A" ]
        , input
            [ onEnter AddTag
            , onInput NewTagInput
            , value model.newTag
            ]
            []
        , div [] (List.map tagView model.tags)
        ]


init : ( Model, Cmd Msg )
init =
    ( Model [] "", Cmd.none )


main : Program Never Model Msg
main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }<commit_msg>LearnA contenteditable dropping newlines<commit_after>module LearnA exposing (main)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (on, onInput)
import Json.Decode as JD


type Msg
    = SetTextContent String


type alias Model =
    { textContent : String
    }


textContentDecoder : JD.Decoder String
textContentDecoder =
    JD.at [ "target", "textContent" ] JD.string


onEdit : (String -> value) -> Attribute value
onEdit tagger =
    on "input" (JD.map tagger textContentDecoder)


update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
    case message of
        SetTextContent textContent ->
            let
                _ =
                    Debug.log "update textContent" (textContent ++ "foo\nbar\nbaz")
            in
                ( { model | textContent = textContent }, Cmd.none )


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.none


view : Model -> Html Msg
view model =
    div []
        [ h1 []
            [ text "Content Editable Drops Newlines"
            , p [] [ text "Edit the div below. Put some newlines. They will not be in the String in the model." ]
            ]
        , div
            [ contenteditable True
            , onEdit SetTextContent
            ]
            [ text "Edit this div including some newlines" ]
        , div [ style [ ( "white-space", "pre" ) ] ] [ text model.textContent ]
        ]


init : ( Model, Cmd Msg )
init =
    ( Model "", Cmd.none )


main : Program Never Model Msg
main =
    Html.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }
{'fraction_non_alphanumeric': 0.09981515711645102, 'fraction_numerical': 0.0009242144177449168, 'mean_word_length': 1.7331649831649831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2083905', 'n_tokens_mistral': 992, 'n_tokens_neox': 940, 'n_words': 297}