Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html is cleaned up after inserting an image or link when the composer is empty #379

Open
ungue opened this issue May 3, 2017 · 0 comments

Comments

@ungue
Copy link

ungue commented May 3, 2017

Hi,

When composer is empty and you use insertImage or insertLink commands, nothing is inserted in the html.
The issue is due to an invalid asynchronous test in this piece of code:

      if (!this.config.useLineBreaks) {
        dom.observe(this.element, ["focus"], function() {
          if (that.isEmpty()) {
            setTimeout(function() {
              var paragraph = that.doc.createElement("P");
              that.element.innerHTML = "";
              that.element.appendChild(paragraph);
              if (!browser.displaysCaretInEmptyContentEditableCorrectly()) {
                paragraph.innerHTML = "<br>";
                that.selection.setBefore(paragraph.firstChild);
              } else {
                that.selection.selectNode(paragraph, true);
              }
            }, 0);
          }
        });
      }

Note that that.isEmpty is checked outside the asynchronous block, so, this initially have a value of true, however, when the async code is executed, we have a valid html <p><img ...></p> but we are treating this as if it was empty because of the previous condition.

In order to solve this, this is as easy as moving the condition inside the async block:

      if (!this.config.useLineBreaks) {
        dom.observe(this.element, ["focus"], function() {
            setTimeout(function() {
               if (that.isEmpty()) {
                  var paragraph = that.doc.createElement("P");
                  that.element.innerHTML = "";
                  that.element.appendChild(paragraph);
                  if (!browser.displaysCaretInEmptyContentEditableCorrectly()) {
                    paragraph.innerHTML = "<br>";
                    that.selection.setBefore(paragraph.firstChild);
                  } else {
                    that.selection.selectNode(paragraph, true);
                  }
               }
            }, 0);
          }
        });
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant