jakiestfu / Medium.js

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

set cursor after the insert elem possible ? #206

Open flozero opened 7 years ago

flozero commented 7 years ago

hello i am using angularjs 1.6 with components. All is working fine but on my insert invent i would like to set the cursor after the span inserted. Because if i'm adding a class it will be add to all after because all will be in the span elem

 `    var article = document.getElementById('editor');
       var container = article.parentNode;
       var medium;

  this.$onInit = function() {
    setTimeout(function(){
      medium = new Medium({
          element: article,
          mode: Medium.richMode,
          placeholder: 'Your Article',
          tags: null,
          attributes: null
      });

      container.querySelector('.insert').onmousedown = function(evt) {
          var child = document.createElement('span');
          child.innerHTML = evt.target.attributes.data.value;
          child.addEventListener("click", function(evt){
            console.log(this);
            this.remove();
          });
          medium.focus();
          medium.insertHtml(child)
          medium.cursor.set(this.html.text(el).length, el);
          return false;
      };

    }, 0);`