From c25bfe8a9f3ee4d8fadc1c3bc564a38f3f37dc0e Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 17 Jun 2015 15:36:29 +0700 Subject: [PATCH] Fix error thrown inserting tree fragment at start/end of document. --- source/Range.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/Range.js b/source/Range.js index 006a5f4..0ad115a 100644 --- a/source/Range.js +++ b/source/Range.js @@ -250,8 +250,9 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { nodeBeforeSplit = next.previousSibling; } if ( !startContainer.parentNode ) { - startContainer = nodeBeforeSplit; - startOffset = nodeBeforeSplit.childNodes.length; + startContainer = nodeBeforeSplit || next.parentNode; + startOffset = nodeBeforeSplit ? + nodeBeforeSplit.childNodes.length : 0; } // Merge inserted containers with edges of split if ( isContainer( next ) ) { @@ -277,7 +278,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { endOffset = prev.childNodes.length; } // Merge inserted containers with edges of split - if ( isContainer( nodeAfterSplit ) ) { + if ( nodeAfterSplit && isContainer( nodeAfterSplit ) ) { mergeContainers( nodeAfterSplit ); }