0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Fix error thrown inserting tree fragment at start/end of document.

This commit is contained in:
Neil Jenkins 2015-06-17 15:36:29 +07:00
parent c29a8c639b
commit 42139c8399

View file

@ -250,8 +250,9 @@ var insertTreeFragmentIntoRange = function ( range, frag ) {
nodeBeforeSplit = next.previousSibling; nodeBeforeSplit = next.previousSibling;
} }
if ( !startContainer.parentNode ) { if ( !startContainer.parentNode ) {
startContainer = nodeBeforeSplit; startContainer = nodeBeforeSplit || next.parentNode;
startOffset = nodeBeforeSplit.childNodes.length; startOffset = nodeBeforeSplit ?
nodeBeforeSplit.childNodes.length : 0;
} }
// Merge inserted containers with edges of split // Merge inserted containers with edges of split
if ( isContainer( next ) ) { if ( isContainer( next ) ) {
@ -277,7 +278,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) {
endOffset = prev.childNodes.length; endOffset = prev.childNodes.length;
} }
// Merge inserted containers with edges of split // Merge inserted containers with edges of split
if ( isContainer( nodeAfterSplit ) ) { if ( nodeAfterSplit && isContainer( nodeAfterSplit ) ) {
mergeContainers( nodeAfterSplit ); mergeContainers( nodeAfterSplit );
} }