elm-rte-toolkit icon indicating copy to clipboard operation
elm-rte-toolkit copied to clipboard

`joinBackward` and `joinForward` are not correct

Open tgelu opened this issue 4 years ago • 1 comments

These 2 functions are documented as such:

_joinBackward_
If the selection is collapsed and at the start of a text block, **tries to join the current block the previous one**.
_joinForward_
If the selection is collapsed and at the end of a text block, **tries to join the current block the next one**.

(emphases are mine)

But in reality they both try to join either backward or forward with the first text block it finds, not the previous block (whatever it might be). That is to say that if the previous/next block is not text it keeps searching until it can join with one instead of failing.

This has unexpected consequences. One such example would be from the Commands.defaultCommandMap where we have this sequence:

    , ( "joinBackward", transform joinBackward )
    , ( "selectBackward", transform selectBackward )

So if one removes a paragraph which is right after a selectable leaf block, for example, the cursor jumps over the selectable leaf block and lands at the end of the previous paragraph (if there is one). This is because joinBackward succeeds when one would expect it to fail and for selectBackward to succeed instead.

I presume the error is because in both commands we try to findPreviousTextBlock and findNextTextBlock which use findBackwardFromExclusive and findForwardFromExclusive respectively which search until the condition (is text block) is met.

Thank you so much for this package, it is brilliant! One of the best experiences (if not the best) I had building a WYSIWYG editor.

tgelu avatar Oct 05 '20 20:10 tgelu

Hey sorry for not responding to this very quickly. It's not the best excuse, but I've been busy with other projects, and reading over this bug it seemed to be pretty complex behavior so I was a little intimidated. Anyway, I'll take a look this weekend and give a more detailed response and hopefully we can come up with a good fix, or at the very least fix the documentation. Thank you for reporting this!

Edit: still looking at this

mweiss avatar Oct 31 '20 07:10 mweiss