mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -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:
parent
ac14985583
commit
0ba91e627d
2 changed files with 17 additions and 17 deletions
File diff suppressed because one or more lines are too long
|
@ -1217,24 +1217,24 @@
|
||||||
// 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;
|
}
|
||||||
}
|
// If this is not inside a block, replace it by wrapping
|
||||||
// If this is not inside a block, replace it by wrapping
|
// inlines in DIV.
|
||||||
// inlines in DIV.
|
if ( !block.isBlock() ) {
|
||||||
if ( !block.isBlock() ) {
|
wrapTopLevelInline( block, 'DIV' );
|
||||||
wrapTopLevelInline( block, 'DIV' );
|
}
|
||||||
}
|
// If in a block we can split, split it instead, but only if there
|
||||||
// If in a block we can split, split it instead
|
// is actual text content in the block. Otherwise, the <br> is a
|
||||||
else if ( tagAfterSplit[ block.nodeName ] ) {
|
// placeholder to stop the block from collapsing, so we must leave
|
||||||
splitBlock( block, br.parentNode, br );
|
// it.
|
||||||
br.detach();
|
else if ( tagAfterSplit[ block.nodeName ] &&
|
||||||
}
|
/\S/.test( block.textContent ) ) {
|
||||||
// Otherwise leave the br alone.
|
splitBlock( block, br.parentNode, br );
|
||||||
} else {
|
|
||||||
br.detach();
|
br.detach();
|
||||||
}
|
}
|
||||||
|
// Otherwise leave the br alone.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue