mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Merge adjacent text nodes after extracting range.
This commit is contained in:
parent
5865eb032a
commit
ed0ebdae49
3 changed files with 40 additions and 8 deletions
|
@ -723,7 +723,7 @@ var extractContentsOfRange = function ( range, common ) {
|
||||||
var endNode = split( endContainer, endOffset, common ),
|
var endNode = split( endContainer, endOffset, common ),
|
||||||
startNode = split( startContainer, startOffset, common ),
|
startNode = split( startContainer, startOffset, common ),
|
||||||
frag = common.ownerDocument.createDocumentFragment(),
|
frag = common.ownerDocument.createDocumentFragment(),
|
||||||
next;
|
next, before, after;
|
||||||
|
|
||||||
// End node will be null if at end of child nodes list.
|
// End node will be null if at end of child nodes list.
|
||||||
while ( startNode !== endNode ) {
|
while ( startNode !== endNode ) {
|
||||||
|
@ -732,9 +732,25 @@ var extractContentsOfRange = function ( range, common ) {
|
||||||
startNode = next;
|
startNode = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
range.setStart( common, endNode ?
|
startContainer = common;
|
||||||
|
startOffset = endNode ?
|
||||||
indexOf.call( common.childNodes, endNode ) :
|
indexOf.call( common.childNodes, endNode ) :
|
||||||
common.childNodes.length );
|
common.childNodes.length;
|
||||||
|
|
||||||
|
// Merge text nodes if adjacent. IE10 in particular will not focus
|
||||||
|
// between two text nodes
|
||||||
|
after = common.childNodes[ startOffset ];
|
||||||
|
before = after && after.previousSibling;
|
||||||
|
if ( before &&
|
||||||
|
before.nodeType === TEXT_NODE &&
|
||||||
|
after.nodeType === TEXT_NODE ) {
|
||||||
|
startContainer = before;
|
||||||
|
startOffset = before.length;
|
||||||
|
before.appendData( after.data );
|
||||||
|
detach( after );
|
||||||
|
}
|
||||||
|
|
||||||
|
range.setStart( startContainer, startOffset );
|
||||||
range.collapse( true );
|
range.collapse( true );
|
||||||
|
|
||||||
fixCursor( common );
|
fixCursor( common );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -134,7 +134,7 @@ var extractContentsOfRange = function ( range, common ) {
|
||||||
var endNode = split( endContainer, endOffset, common ),
|
var endNode = split( endContainer, endOffset, common ),
|
||||||
startNode = split( startContainer, startOffset, common ),
|
startNode = split( startContainer, startOffset, common ),
|
||||||
frag = common.ownerDocument.createDocumentFragment(),
|
frag = common.ownerDocument.createDocumentFragment(),
|
||||||
next;
|
next, before, after;
|
||||||
|
|
||||||
// End node will be null if at end of child nodes list.
|
// End node will be null if at end of child nodes list.
|
||||||
while ( startNode !== endNode ) {
|
while ( startNode !== endNode ) {
|
||||||
|
@ -143,9 +143,25 @@ var extractContentsOfRange = function ( range, common ) {
|
||||||
startNode = next;
|
startNode = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
range.setStart( common, endNode ?
|
startContainer = common;
|
||||||
|
startOffset = endNode ?
|
||||||
indexOf.call( common.childNodes, endNode ) :
|
indexOf.call( common.childNodes, endNode ) :
|
||||||
common.childNodes.length );
|
common.childNodes.length;
|
||||||
|
|
||||||
|
// Merge text nodes if adjacent. IE10 in particular will not focus
|
||||||
|
// between two text nodes
|
||||||
|
after = common.childNodes[ startOffset ];
|
||||||
|
before = after && after.previousSibling;
|
||||||
|
if ( before &&
|
||||||
|
before.nodeType === TEXT_NODE &&
|
||||||
|
after.nodeType === TEXT_NODE ) {
|
||||||
|
startContainer = before;
|
||||||
|
startOffset = before.length;
|
||||||
|
before.appendData( after.data );
|
||||||
|
detach( after );
|
||||||
|
}
|
||||||
|
|
||||||
|
range.setStart( startContainer, startOffset );
|
||||||
range.collapse( true );
|
range.collapse( true );
|
||||||
|
|
||||||
fixCursor( common );
|
fixCursor( common );
|
||||||
|
|
Loading…
Reference in a new issue