0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 23:40:35 -05:00

Rewrite all <br>s in cleanupBRs fn.

Previously, we were just removing <br>s that didn't have siblings on both sides. A better test is whether the containing block has any non-whitespace text content. If it does, the <br> is a line break and we can just split the block. If it doesn't though, we need to leave the <br> as a placeholder, to ensure the block doesn't collapse to 0 height.
This commit is contained in:
Neil Jenkins 2013-02-22 15:07:25 +11:00
parent ac14985583
commit 0ba91e627d
2 changed files with 17 additions and 17 deletions

File diff suppressed because one or more lines are too long

View file

@ -1217,7 +1217,6 @@
// Cleanup may have removed it // Cleanup may have removed it
block = br.parentNode; block = br.parentNode;
if ( !block ) { continue; } if ( !block ) { continue; }
if ( br.nextSibling && br.previousSibling ) {
while ( block.isInline() ) { while ( block.isInline() ) {
block = block.parentNode; block = block.parentNode;
} }
@ -1226,15 +1225,16 @@
if ( !block.isBlock() ) { if ( !block.isBlock() ) {
wrapTopLevelInline( block, 'DIV' ); wrapTopLevelInline( block, 'DIV' );
} }
// If in a block we can split, split it instead // If in a block we can split, split it instead, but only if there
else if ( tagAfterSplit[ block.nodeName ] ) { // is actual text content in the block. Otherwise, the <br> is a
// placeholder to stop the block from collapsing, so we must leave
// it.
else if ( tagAfterSplit[ block.nodeName ] &&
/\S/.test( block.textContent ) ) {
splitBlock( block, br.parentNode, br ); splitBlock( block, br.parentNode, br );
br.detach(); br.detach();
} }
// Otherwise leave the br alone. // Otherwise leave the br alone.
} else {
br.detach();
}
} }
}; };