0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Skip placeholder BRs when moving range up/down tree

This commit is contained in:
Neil Jenkins 2016-09-25 21:43:47 +01:00
parent deb8bd8b88
commit d8239d2570
3 changed files with 40 additions and 6 deletions

View file

@ -1033,6 +1033,7 @@ var moveRangeBoundariesDownTree = function ( range ) {
startOffset = range.startOffset,
endContainer = range.endContainer,
endOffset = range.endOffset,
maySkipBR = true,
child;
while ( startContainer.nodeType !== TEXT_NODE ) {
@ -1047,6 +1048,11 @@ var moveRangeBoundariesDownTree = function ( range ) {
while ( endContainer.nodeType !== TEXT_NODE ) {
child = endContainer.childNodes[ endOffset - 1 ];
if ( !child || isLeaf( child ) ) {
if ( maySkipBR && child && child.nodeName === 'BR' ) {
endOffset -= 1;
maySkipBR = false;
continue;
}
break;
}
endContainer = child;
@ -1079,6 +1085,7 @@ var moveRangeBoundariesUpTree = function ( range, common ) {
startOffset = range.startOffset,
endContainer = range.endContainer,
endOffset = range.endOffset,
maySkipBR = true,
parent;
if ( !common ) {
@ -1091,8 +1098,18 @@ var moveRangeBoundariesUpTree = function ( range, common ) {
startContainer = parent;
}
while ( endContainer !== common &&
endOffset === getLength( endContainer ) ) {
while ( true ) {
if ( maySkipBR &&
endContainer.nodeType !== TEXT_NODE &&
endContainer.childNodes[ endOffset ] &&
endContainer.childNodes[ endOffset ].nodeName === 'BR' ) {
endOffset += 1;
maySkipBR = false;
}
if ( endContainer === common ||
endOffset !== getLength( endContainer ) ) {
break;
}
parent = endContainer.parentNode;
endOffset = indexOf.call( parent.childNodes, endContainer ) + 1;
endContainer = parent;

File diff suppressed because one or more lines are too long

View file

@ -341,6 +341,7 @@ var moveRangeBoundariesDownTree = function ( range ) {
startOffset = range.startOffset,
endContainer = range.endContainer,
endOffset = range.endOffset,
maySkipBR = true,
child;
while ( startContainer.nodeType !== TEXT_NODE ) {
@ -355,6 +356,11 @@ var moveRangeBoundariesDownTree = function ( range ) {
while ( endContainer.nodeType !== TEXT_NODE ) {
child = endContainer.childNodes[ endOffset - 1 ];
if ( !child || isLeaf( child ) ) {
if ( maySkipBR && child && child.nodeName === 'BR' ) {
endOffset -= 1;
maySkipBR = false;
continue;
}
break;
}
endContainer = child;
@ -387,6 +393,7 @@ var moveRangeBoundariesUpTree = function ( range, common ) {
startOffset = range.startOffset,
endContainer = range.endContainer,
endOffset = range.endOffset,
maySkipBR = true,
parent;
if ( !common ) {
@ -399,8 +406,18 @@ var moveRangeBoundariesUpTree = function ( range, common ) {
startContainer = parent;
}
while ( endContainer !== common &&
endOffset === getLength( endContainer ) ) {
while ( true ) {
if ( maySkipBR &&
endContainer.nodeType !== TEXT_NODE &&
endContainer.childNodes[ endOffset ] &&
endContainer.childNodes[ endOffset ].nodeName === 'BR' ) {
endOffset += 1;
maySkipBR = false;
}
if ( endContainer === common ||
endOffset !== getLength( endContainer ) ) {
break;
}
parent = endContainer.parentNode;
endOffset = indexOf.call( parent.childNodes, endContainer ) + 1;
endContainer = parent;