jakiestfu / Medium.js

A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)

Home Page:http://jakiestfu.github.io/Medium.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set cursor after the insert elem possible ?

flozero opened this issue · comments

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);`