jakiestfu / Medium.js

A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)
http://jakiestfu.github.io/Medium.js/
4.39k stars 403 forks source link

insertHtml Prepends Content #203

Open vhmth opened 7 years ago

vhmth commented 7 years ago

I noticed that when I try to insertHtml('<ul><li></li></ul>'); to a Medium.js instance after calling medium.focus() off a button click, the content is always prepended. Not sure what's exactly going on, but I figured it may be because calling medium.focus() results in the cursor unconditionally going to the beginning of the text area.

I've made a video showcasing what's going on here:

https://www.opentest.co/share/c509f0d0aabe11e69e53f587dba00be5

I would be happy to open a PR to get this fixed ASAP if someone has an inkling of suspicion as to what may be going on here. The example on the GH page seems to work fine for me so perhaps it's some nuance of my local setup? I am including rangy (both core and the other sub lib) as well as undo.js.

vhmth commented 7 years ago

Upon a bit more investigation, it seems like span#wedge element gets placed at the start of my content div in Medium.Injector.prototype.inject when this.insertHtml is called. Strange because that will then make parent.insertBefore(html[i], wedge); insert the list at the beginning.