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

Correctly check if <br> makes a line break.

The previous test was incorrect. A <br> actually introduces a line break if
there is any non-whitespace after it in the block or if there is another <br>
after it in the block. It is irrelevant what comes before it in the block.
This commit is contained in:
Neil Jenkins 2013-03-08 17:14:11 +11:00
parent a12f6905a5
commit 768f4420b9
2 changed files with 11 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -11,6 +11,7 @@
var DOCUMENT_POSITION_PRECEDING = 2, // Node.DOCUMENT_POSITION_PRECEDING
ELEMENT_NODE = 1, // Node.ELEMENT_NODE,
TEXT_NODE = 3, // Node.TEXT_NODE,
SHOW_ELEMENT = 1, // NodeFilter.SHOW_ELEMENT,
SHOW_TEXT = 4, // NodeFilter.SHOW_TEXT,
FILTER_ACCEPT = 1, // NodeFilter.FILTER_ACCEPT,
FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP;
@ -1220,20 +1221,21 @@
};
var notWSTextNode = function ( node ) {
return notWS.test( node.data ) ? FILTER_ACCEPT : FILTER_SKIP;
return ( node.nodeType === ELEMENT_NODE ?
node.nodeName === 'BR' :
notWS.test( node.data ) ) ?
FILTER_ACCEPT : FILTER_SKIP;
};
var isLineBreak = function ( br ) {
var block = br.parentNode;
var block = br.parentNode,
walker;
while ( block.isInline() ) {
block = block.parentNode;
}
var walker = new TreeWalker( block, SHOW_TEXT, notWSTextNode );
walker = new TreeWalker(
block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode );
walker.currentNode = br;
if ( !walker.nextNode() ) {
return false;
}
walker.currentNode = br;
return !!walker.previousNode();
return !!walker.nextNode();
};
// <br> elements are treated specially, and differently depending on the