mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
Fix deletion of range when start or end is at edge of block.
If the selection starts and ends in the middle of blocks, we need to merge these after extracting the range. But we need to be careful not to merge if the selection ends at a block, as we end up merging into a block that wasn't selected.
This commit is contained in:
parent
715166b95d
commit
c190fab9fd
3 changed files with 32 additions and 8 deletions
|
@ -766,8 +766,16 @@ var extractContentsOfRange = function ( range, common ) {
|
|||
|
||||
var deleteContentsOfRange = function ( range ) {
|
||||
// Move boundaries up as much as possible to reduce need to split.
|
||||
// But we need to check whether we've moved the boundary outside of a
|
||||
// block. If so, the entire block will be removed, so we shouldn't merge
|
||||
// later.
|
||||
moveRangeBoundariesUpTree( range );
|
||||
|
||||
var startBlock = range.startContainer,
|
||||
endBlock = range.endContainer,
|
||||
needsMerge = ( isInline( startBlock ) || isBlock( startBlock ) ) &&
|
||||
( isInline( endBlock ) || isBlock( endBlock ) );
|
||||
|
||||
// Remove selected range
|
||||
extractContentsOfRange( range );
|
||||
|
||||
|
@ -777,11 +785,13 @@ var deleteContentsOfRange = function ( range ) {
|
|||
moveRangeBoundariesDownTree( range );
|
||||
|
||||
// If we split into two different blocks, merge the blocks.
|
||||
var startBlock = getStartBlockOfRange( range ),
|
||||
if ( needsMerge ) {
|
||||
startBlock = getStartBlockOfRange( range );
|
||||
endBlock = getEndBlockOfRange( range );
|
||||
if ( startBlock && endBlock && startBlock !== endBlock ) {
|
||||
mergeWithBlock( startBlock, endBlock, range );
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure block has necessary children
|
||||
if ( startBlock ) {
|
||||
|
@ -794,6 +804,8 @@ var deleteContentsOfRange = function ( range ) {
|
|||
if ( !child || child.nodeName === 'BR' ) {
|
||||
fixCursor( body );
|
||||
range.selectNodeContents( body.firstChild );
|
||||
} else {
|
||||
range.collapse( false );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -134,8 +134,16 @@ var extractContentsOfRange = function ( range, common ) {
|
|||
|
||||
var deleteContentsOfRange = function ( range ) {
|
||||
// Move boundaries up as much as possible to reduce need to split.
|
||||
// But we need to check whether we've moved the boundary outside of a
|
||||
// block. If so, the entire block will be removed, so we shouldn't merge
|
||||
// later.
|
||||
moveRangeBoundariesUpTree( range );
|
||||
|
||||
var startBlock = range.startContainer,
|
||||
endBlock = range.endContainer,
|
||||
needsMerge = ( isInline( startBlock ) || isBlock( startBlock ) ) &&
|
||||
( isInline( endBlock ) || isBlock( endBlock ) );
|
||||
|
||||
// Remove selected range
|
||||
extractContentsOfRange( range );
|
||||
|
||||
|
@ -145,11 +153,13 @@ var deleteContentsOfRange = function ( range ) {
|
|||
moveRangeBoundariesDownTree( range );
|
||||
|
||||
// If we split into two different blocks, merge the blocks.
|
||||
var startBlock = getStartBlockOfRange( range ),
|
||||
if ( needsMerge ) {
|
||||
startBlock = getStartBlockOfRange( range );
|
||||
endBlock = getEndBlockOfRange( range );
|
||||
if ( startBlock && endBlock && startBlock !== endBlock ) {
|
||||
mergeWithBlock( startBlock, endBlock, range );
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure block has necessary children
|
||||
if ( startBlock ) {
|
||||
|
@ -162,6 +172,8 @@ var deleteContentsOfRange = function ( range ) {
|
|||
if ( !child || child.nodeName === 'BR' ) {
|
||||
fixCursor( body );
|
||||
range.selectNodeContents( body.firstChild );
|
||||
} else {
|
||||
range.collapse( false );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue