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

Copy/Paste in IE 11 no longer works #320

Open
atopper opened this issue Apr 3, 2014 · 2 comments
Open

Copy/Paste in IE 11 no longer works #320

atopper opened this issue Apr 3, 2014 · 2 comments
Labels

Comments

@atopper
Copy link

atopper commented Apr 3, 2014

You can't copy and paste text in the editor in IE 11.

The following code in epiceditor.js no longer works because 'selection' is no longer supported and 'createRange' is no longer supported on the getSelection() replacement:

    self.editorIframeDocument.selection.createRange().pasteHTML(content);

I played around a little and this seems to work. May not be the best way but...

    if (self.editorIframeDocument.selection) {
        self.editorIframeDocument.selection.createRange().pasteHTML(content);
    } else {
        var rng = self.editorIframeDocument.getSelection().getRangeAt(0);
        rng.deleteContents();
        var textNode = self.editorIframeDocument.createTextNode(content);
        rng.insertNode(textNode);
    }
@OscarGodson
Copy link
Owner

Does that work in all browsers? If so, mind sending a PR?

@atopper
Copy link
Author

atopper commented Apr 4, 2014

Thanks for the quick reply.

The change works (or more likely, has no affect) on chrome and FF. The new
code (bold) only runs if a JS error would have been thrown in the original
case, so it can't be any worse (not fantastic testing, I admit). I'll
consider a PR, but am not sure I'll get to it any time soon.

function pasteHandler(e) {
  var content;
  if (e.clipboardData) {
    //FF 22, Webkit, "standards"
    e.preventDefault();
    content = e.clipboardData.getData("text/plain");
    self.editorIframeDocument.execCommand("insertText", false, content);
  }
  else if (window.clipboardData) {
    //IE, "nasty"
    e.preventDefault();
    content = window.clipboardData.getData("Text");
    content = content.replace(/</g, '&lt;');
    content = content.replace(/>/g, '&gt;');
    content = content.replace(/\n/g, '<br>');
    content = content.replace(/\r/g, ''); // for ie
    content = content.replace(/<br>\s/g, '<br>&nbsp;');
    content = content.replace(/\s\s\s/g, '&nbsp; &nbsp;');
    content = content.replace(/\s\s/g, '&nbsp; ');
    if (self.editorIframeDocument.selection) {

self.editorIframeDocument.selection.createRange().pasteHTML(content);
}* else {*

  •        var rng =
    
    self.editorIframeDocument.getSelection().getRangeAt(0);*
  •        rng.deleteContents();*
    
  •        var textNode =
    
    self.editorIframeDocument.createTextNode(content);*
  •        rng.insertNode(textNode);*
    
  •    }*
    
    }
    }

On Thu, Apr 3, 2014 at 6:23 PM, Oscar Godson [email protected]:

Does that work in all browsers? If so, mind sending a PR?

Reply to this email directly or view it on GitHubhttps://github.com//issues/320#issuecomment-39512445
.

Andrew Top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants