Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Internet Explorer 11 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Apr 19, 2019
1 parent 8c39bdb commit d352ac6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/dataprocessor/htmldataprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export default class HtmlDataProcessor {
_toDom( data ) {
const document = this._domParser.parseFromString( data, 'text/html' );
const fragment = document.createDocumentFragment();

if ( data == '' ) {
return fragment;
}

const nodes = document.body.childNodes;

while ( nodes.length > 0 ) {
Expand Down
32 changes: 19 additions & 13 deletions src/view/domconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @module engine/view/domconverter
*/

/* globals document, Node, NodeFilter, Text */
/* globals document, Node, NodeFilter */

import ViewText from './text';
import ViewElement from './element';
Expand All @@ -24,6 +24,7 @@ import getAncestors from '@ckeditor/ckeditor5-utils/src/dom/getancestors';
import getCommonAncestor from '@ckeditor/ckeditor5-utils/src/dom/getcommonancestor';
import isText from '@ckeditor/ckeditor5-utils/src/dom/istext';
import { isElement } from 'lodash-es';
import env from '@ckeditor/ckeditor5-utils/src/env';

/**
* DomConverter is a set of tools to do transformations between DOM nodes and view nodes. It also handles
Expand Down Expand Up @@ -995,7 +996,7 @@ export default class DomConverter {
// This means that the text node starts/end with normal space instead of non-breaking space.
// This causes a problem because the normal space would be removed in `.replace` calls above. To prevent that,
// the inline filler is removed only after the data is initially processed (by the `.replace` above). See ckeditor5#692.
data = getDataWithoutFiller( new Text( data ) );
data = getDataWithoutFiller( document.createTextNode( data ) );

// At this point we should have removed all whitespaces from DOM text data.

Expand Down Expand Up @@ -1121,19 +1122,24 @@ export default class DomConverter {
const document = node.ownerDocument;
const topmostParent = getAncestors( node )[ 0 ];

const treeWalker = document.createTreeWalker( topmostParent, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT, {
acceptNode( node ) {
if ( isText( node ) ) {
return NodeFilter.FILTER_ACCEPT;
}

if ( node.tagName == 'BR' ) {
return NodeFilter.FILTER_ACCEPT;
}
const acceptNode = node => {
if ( isText( node ) ) {
return NodeFilter.FILTER_ACCEPT;
}

return NodeFilter.FILTER_SKIP;
if ( node.tagName == 'BR' ) {
return NodeFilter.FILTER_ACCEPT;
}
} );

return NodeFilter.FILTER_SKIP;
};

const treeWalker = document.createTreeWalker(
topmostParent,
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,
env.isIe11 ? acceptNode : { acceptNode },
false
);

treeWalker.currentNode = node;

Expand Down
42 changes: 32 additions & 10 deletions src/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals Node */
/* globals Node, document */

/**
* @module engine/view/renderer
Expand Down Expand Up @@ -697,13 +697,19 @@ export default class Renderer {
if ( !container ) {
this._fakeSelectionContainer = container = domDocument.createElement( 'div' );

Object.assign( container.style, {
position: 'fixed',
top: 0,
left: '-9999px',
// See https://github.com/ckeditor/ckeditor5/issues/752.
width: '42px'
} );
if ( env.isIe11 ) {
Object.assign( container.style, {
display: 'none'
} );
} else {
Object.assign( container.style, {
position: 'fixed',
top: 0,
left: '-9999px',
// See https://github.com/ckeditor/ckeditor5/issues/752.
width: '42px'
} );
}

// Fill it with a text node so we can update it later.
container.textContent = '\u00A0';
Expand Down Expand Up @@ -754,8 +760,24 @@ export default class Renderer {
// Otherwise, FF may throw an error (https://github.com/ckeditor/ckeditor5/issues/721).
domRoot.focus();

domSelection.collapse( anchor.parent, anchor.offset );
domSelection.extend( focus.parent, focus.offset );
if ( env.isIe11 ) {
// IE 11 does not support `Selection#extend()`.
// I tried to simply polyfill it but it was failing for some reason in unit tests.
const domRange = document.createRange();

domRange.setStart( anchor.parent, anchor.offset );
domRange.setEnd( focus.parent, focus.offset );

if ( domRange.collapsed ) {
domRange.setEnd( anchor.parent, anchor.offset );
}

domSelection.removeAllRanges();
domSelection.addRange( domRange );
} else {
domSelection.collapse( anchor.parent, anchor.offset );
domSelection.extend( focus.parent, focus.offset );
}

// Firefox–specific hack (https://github.com/ckeditor/ckeditor5-engine/issues/1439).
if ( env.isGecko ) {
Expand Down
4 changes: 3 additions & 1 deletion tests/view/observer/selectionobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe( 'SelectionObserver', () => {
} );

afterEach( () => {
domRoot.parentElement.removeChild( domRoot );
if ( domRoot.parentElement ) {
domRoot.parentElement.removeChild( domRoot );
}

view.destroy();
} );
Expand Down
7 changes: 6 additions & 1 deletion tests/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3795,7 +3795,12 @@ describe( 'Renderer', () => {

// Checks if every node in DOM tree is mapped to the view.
function checkMappings() {
const domWalker = document.createTreeWalker( domRoot, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT );
const domWalker = document.createTreeWalker(
domRoot,
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
env.isIe11 ? () => true : null,
false
);

while ( domWalker.nextNode() ) {
const node = domWalker.currentNode;
Expand Down

0 comments on commit d352ac6

Please sign in to comment.