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:
parent
a12f6905a5
commit
768f4420b9
2 changed files with 11 additions and 9 deletions
File diff suppressed because one or more lines are too long
|
@ -11,6 +11,7 @@
|
||||||
var DOCUMENT_POSITION_PRECEDING = 2, // Node.DOCUMENT_POSITION_PRECEDING
|
var DOCUMENT_POSITION_PRECEDING = 2, // Node.DOCUMENT_POSITION_PRECEDING
|
||||||
ELEMENT_NODE = 1, // Node.ELEMENT_NODE,
|
ELEMENT_NODE = 1, // Node.ELEMENT_NODE,
|
||||||
TEXT_NODE = 3, // Node.TEXT_NODE,
|
TEXT_NODE = 3, // Node.TEXT_NODE,
|
||||||
|
SHOW_ELEMENT = 1, // NodeFilter.SHOW_ELEMENT,
|
||||||
SHOW_TEXT = 4, // NodeFilter.SHOW_TEXT,
|
SHOW_TEXT = 4, // NodeFilter.SHOW_TEXT,
|
||||||
FILTER_ACCEPT = 1, // NodeFilter.FILTER_ACCEPT,
|
FILTER_ACCEPT = 1, // NodeFilter.FILTER_ACCEPT,
|
||||||
FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP;
|
FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP;
|
||||||
|
@ -1220,20 +1221,21 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var notWSTextNode = function ( node ) {
|
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 isLineBreak = function ( br ) {
|
||||||
var block = br.parentNode;
|
var block = br.parentNode,
|
||||||
|
walker;
|
||||||
while ( block.isInline() ) {
|
while ( block.isInline() ) {
|
||||||
block = block.parentNode;
|
block = block.parentNode;
|
||||||
}
|
}
|
||||||
var walker = new TreeWalker( block, SHOW_TEXT, notWSTextNode );
|
walker = new TreeWalker(
|
||||||
|
block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode );
|
||||||
walker.currentNode = br;
|
walker.currentNode = br;
|
||||||
if ( !walker.nextNode() ) {
|
return !!walker.nextNode();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
walker.currentNode = br;
|
|
||||||
return !!walker.previousNode();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// <br> elements are treated specially, and differently depending on the
|
// <br> elements are treated specially, and differently depending on the
|
||||||
|
|
Loading…
Reference in a new issue