Inserting hr before non empty paragraph
y-lohse opened this issue · 1 comments
In 7b45776, prevSibling
is assigned the previousSibling
of selection.anchorNode
. The problem is that when the user presses enter and the caret is at the beginning of a non-empty paragraph, selection.anchorNode
is the text node inside the paragraph, not the paragprah itself.
Because of this, inserting a hr before an existing paragraph is broken right now, as prevSibling
isn't the expected node.
In that situation in medium, the first enter keypress inserts an hr, the second a paragraph, etc. This makes it possible to stack empty paragraph and hrs, so that might be a bug on their end but not a very important one.
Using selection.anchorNode.parentNode
is probably not robust enough either, because if the paragraph starts with an i
tag, we'll get the text node inside the i
. This is why I initially used getParentWithTag
but it feels a bit hacky.
Yeah this was pretty nasty, sorry for the oversight there with getting the parent <p>
. Added the case where we check previousSibling.previousSibling
(two empty lines) and replaced one of them with an <hr>
for the insertion case before a non-empty paragraph.
Could you take a look at #31? It'd be nice to get a second pair of eyes on it!