Skip to content

Commit

Permalink
Turn off native insertHTML command for Edge (too buggy for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmielnik committed Feb 7, 2016
1 parent a711034 commit 62cd678
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
12 changes: 2 additions & 10 deletions spec/paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ describe('Pasting content', function () {
{
source: 'Text single word with leading/trailing space',
paste: ' supercalifragilisticexpalidocious ',
// Edge incorrectly remove the leading whitespace >:(
output: isEdge() ? '<div id="editor-inner">supercalifragilisticexpalidocious </div>' : '<div id="editor-inner"> supercalifragilisticexpalidocious </div>'
output: '<div id="editor-inner"> supercalifragilisticexpalidocious </div>'
},
{
source: 'Text multi-word with no line breaks',
Expand Down Expand Up @@ -282,14 +281,7 @@ describe('Pasting content', function () {
selectElementContents(document.getElementById('editor-inner'));

editor.cleanPaste('<label>div one</label><label>div two</label>');

// Edge adds a <font size="2"> tag in here!?!?!
// TODO: Is this just completely wrong?
if (isEdge()) {
expect(this.el.innerHTML).toEqual('Before&nbsp;<span id="editor-inner"><sub><font size="2">div one</font></sub><sub>div two</sub></span>&nbsp;after.');
} else {
expect(this.el.innerHTML).toMatch(new RegExp('^Before(&nbsp;|\\s)(<span id="editor-inner">)?<sub>div one</sub><sub>div two</sub>(</span>)?(&nbsp;|\\s)after\\.$'));
}
expect(this.el.innerHTML).toMatch(new RegExp('^Before(&nbsp;|\\s)(<span id="editor-inner">)?<sub>div one</sub><sub>div two</sub>(</span>)?(&nbsp;|\\s)after\\.$'));
});

it('should respect custom replacements before builtin replacements.', function () {
Expand Down
4 changes: 1 addition & 3 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

if (tag === 'pre') {
event.preventDefault();
// Edge doesn't allow for adding leading whitespace via the 'insertHTML' command
// so for Edge, we'll have to inject the 'tab' manually
MediumEditor.util.insertHTMLCommand(this.options.ownerDocument, ' ', MediumEditor.util.isEdge);
MediumEditor.util.insertHTMLCommand(this.options.ownerDocument, ' ');
}

// Tab to indent list structures!
Expand Down
11 changes: 9 additions & 2 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,17 @@
},

// http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div
insertHTMLCommand: function (doc, html, skipExecCommand) {
insertHTMLCommand: function (doc, html) {
var selection, range, el, fragment, node, lastNode, toReplace;

if (!skipExecCommand && doc.queryCommandSupported('insertHTML')) {
/* Edge's implementation of insertHTML is just buggy right now:
* - Doesn't allow leading white space at the beginning of an element
* - Found a case when a <font size="2"> tag was inserted when calling alignCenter inside a blockquote
*
* There are likely many other bugs, these are just the ones we found so far.
* For now, let's just use the same fallback we did for IE
*/
if (!MediumEditor.util.isEdge && doc.queryCommandSupported('insertHTML')) {
try {
return doc.execCommand('insertHTML', false, html);
} catch (ignore) {}
Expand Down

0 comments on commit 62cd678

Please sign in to comment.