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

Backwards deletion of newline plus character fails (e.g. "\nh") #29

Closed rjdellecese closed 3 years ago

rjdellecese commented 4 years ago

See this Ellie. This issue is also observable in code blocks in the demo. I've injected a bunch of logging statements into the JS to try to understand what's going on, but haven't really made any headway. Any help would be much appreciated!

rjdellecese commented 4 years ago

Actually, it seems to work in Firefox, but not in Safari or Chrome.

rjdellecese commented 4 years ago

I solved this by creating a new inline leaf node that is just an empty span containing a newline ("\n"). Here is an updated Ellie with the solution. This worked for me in Chrome, Firefox, and Safari.

I wonder if it would be better to make RichText.Commands.insertNewline work this way, too? If so, I would be happy to open a PR to do so!

I'll leave this open for the moment in case that would be useful, or else feel to close the issue—my particular problem has been solved.

mweiss commented 3 years ago

That's cool that you solved your particular issue 👍 , it seems like different versions of contenteditable handle newline characters in pre elements in different ways. I don't know your exact requirements, but you may also be able to avoid the issue in a similar way line break element instead of using a newline wrapped in a span. I'll close this ticket for now. Thanks for reporting the issue!