mweiss / elm-rte-toolkit

A toolkit for creating rich text editors in Elm
https://mweiss.github.io/elm-rte-toolkit/
BSD 3-Clause "New" or "Revised" License
149 stars 14 forks source link

Redo doesn't work, wrong sort order #58

Open wolfadex opened 2 months ago

wolfadex commented 2 months ago

RichText.Config.Command.namedCommandListFromKeyboardEvent calls keyboardEventToDictKey internally which sorts the keys before converting the short key to __Short__ whereas the command mapping setup code converts first and then sorts. This causes redo to not work (at least on Mac) in the examples, e.g. in https://mweiss.github.io/elm-rte-toolkit/#/examples/markdown. I have a vendored fork that changes keyboardEventToDictKey to be

keyboardEventToDictKey : String -> KeyboardEvent -> List String
keyboardEventToDictKey shortKey keyboardEvent =
    ([ keyboardEvent.key ]
        |> addShiftKey keyboardEvent
        |> addMetaKey keyboardEvent
        |> addCtrlKey keyboardEvent
        |> addAltKey keyboardEvent
    )
        |> List.map
            (\v ->
                if v == shortKey then
                    short

                else
                    v
            )
        |> List.sort

which fixes the problem. I'll try and make a PR later, but wanted to document it so I don't forget.