mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
Run fixContainers before merging blocks.
In case paste or something has got the document into a weird state with inline content not inside a block.
This commit is contained in:
parent
2fccc317ad
commit
6bafa1d140
3 changed files with 42 additions and 14 deletions
|
@ -1405,8 +1405,15 @@ var keyHandlers = {
|
||||||
// If at beginning of block, merge with previous
|
// If at beginning of block, merge with previous
|
||||||
else if ( rangeDoesStartAtBlockBoundary( range ) ) {
|
else if ( rangeDoesStartAtBlockBoundary( range ) ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var current = getStartBlockOfRange( range ),
|
var current = getStartBlockOfRange( range );
|
||||||
previous = current && getPreviousBlock( current );
|
var previous;
|
||||||
|
if ( !current ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// In case inline data has somehow got between blocks.
|
||||||
|
fixContainer( current.parentNode );
|
||||||
|
// Now get previous block
|
||||||
|
previous = getPreviousBlock( current );
|
||||||
// Must not be at the very beginning of the text area.
|
// Must not be at the very beginning of the text area.
|
||||||
if ( previous ) {
|
if ( previous ) {
|
||||||
// If not editable, just delete whole block.
|
// If not editable, just delete whole block.
|
||||||
|
@ -1451,6 +1458,8 @@ var keyHandlers = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'delete': function ( self, event, range ) {
|
'delete': function ( self, event, range ) {
|
||||||
|
var current, next, originalRange,
|
||||||
|
cursorContainer, cursorOffset, nodeAfterCursor;
|
||||||
self._removeZWS();
|
self._removeZWS();
|
||||||
// Record undo checkpoint.
|
// Record undo checkpoint.
|
||||||
self._recordUndoState( range );
|
self._recordUndoState( range );
|
||||||
|
@ -1464,8 +1473,14 @@ var keyHandlers = {
|
||||||
// If at end of block, merge next into this block
|
// If at end of block, merge next into this block
|
||||||
else if ( rangeDoesEndAtBlockBoundary( range ) ) {
|
else if ( rangeDoesEndAtBlockBoundary( range ) ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var current = getStartBlockOfRange( range ),
|
current = getStartBlockOfRange( range );
|
||||||
next = current && getNextBlock( current );
|
if ( !current ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// In case inline data has somehow got between blocks.
|
||||||
|
fixContainer( current.parentNode );
|
||||||
|
// Now get next block
|
||||||
|
next = getNextBlock( current );
|
||||||
// Must not be at the very end of the text area.
|
// Must not be at the very end of the text area.
|
||||||
if ( next ) {
|
if ( next ) {
|
||||||
// If not editable, just delete whole block.
|
// If not editable, just delete whole block.
|
||||||
|
@ -1494,8 +1509,7 @@ var keyHandlers = {
|
||||||
// But first check if the cursor is just before an IMG tag. If so,
|
// But first check if the cursor is just before an IMG tag. If so,
|
||||||
// delete it ourselves, because the browser won't if it is not
|
// delete it ourselves, because the browser won't if it is not
|
||||||
// inline.
|
// inline.
|
||||||
var originalRange = range.cloneRange(),
|
originalRange = range.cloneRange();
|
||||||
cursorContainer, cursorOffset, nodeAfterCursor;
|
|
||||||
moveRangeBoundariesUpTree( range, self._body );
|
moveRangeBoundariesUpTree( range, self._body );
|
||||||
cursorContainer = range.endContainer;
|
cursorContainer = range.endContainer;
|
||||||
cursorOffset = range.endOffset;
|
cursorOffset = range.endOffset;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -256,8 +256,15 @@ var keyHandlers = {
|
||||||
// If at beginning of block, merge with previous
|
// If at beginning of block, merge with previous
|
||||||
else if ( rangeDoesStartAtBlockBoundary( range ) ) {
|
else if ( rangeDoesStartAtBlockBoundary( range ) ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var current = getStartBlockOfRange( range ),
|
var current = getStartBlockOfRange( range );
|
||||||
previous = current && getPreviousBlock( current );
|
var previous;
|
||||||
|
if ( !current ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// In case inline data has somehow got between blocks.
|
||||||
|
fixContainer( current.parentNode );
|
||||||
|
// Now get previous block
|
||||||
|
previous = getPreviousBlock( current );
|
||||||
// Must not be at the very beginning of the text area.
|
// Must not be at the very beginning of the text area.
|
||||||
if ( previous ) {
|
if ( previous ) {
|
||||||
// If not editable, just delete whole block.
|
// If not editable, just delete whole block.
|
||||||
|
@ -302,6 +309,8 @@ var keyHandlers = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'delete': function ( self, event, range ) {
|
'delete': function ( self, event, range ) {
|
||||||
|
var current, next, originalRange,
|
||||||
|
cursorContainer, cursorOffset, nodeAfterCursor;
|
||||||
self._removeZWS();
|
self._removeZWS();
|
||||||
// Record undo checkpoint.
|
// Record undo checkpoint.
|
||||||
self._recordUndoState( range );
|
self._recordUndoState( range );
|
||||||
|
@ -315,8 +324,14 @@ var keyHandlers = {
|
||||||
// If at end of block, merge next into this block
|
// If at end of block, merge next into this block
|
||||||
else if ( rangeDoesEndAtBlockBoundary( range ) ) {
|
else if ( rangeDoesEndAtBlockBoundary( range ) ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var current = getStartBlockOfRange( range ),
|
current = getStartBlockOfRange( range );
|
||||||
next = current && getNextBlock( current );
|
if ( !current ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// In case inline data has somehow got between blocks.
|
||||||
|
fixContainer( current.parentNode );
|
||||||
|
// Now get next block
|
||||||
|
next = getNextBlock( current );
|
||||||
// Must not be at the very end of the text area.
|
// Must not be at the very end of the text area.
|
||||||
if ( next ) {
|
if ( next ) {
|
||||||
// If not editable, just delete whole block.
|
// If not editable, just delete whole block.
|
||||||
|
@ -345,8 +360,7 @@ var keyHandlers = {
|
||||||
// But first check if the cursor is just before an IMG tag. If so,
|
// But first check if the cursor is just before an IMG tag. If so,
|
||||||
// delete it ourselves, because the browser won't if it is not
|
// delete it ourselves, because the browser won't if it is not
|
||||||
// inline.
|
// inline.
|
||||||
var originalRange = range.cloneRange(),
|
originalRange = range.cloneRange();
|
||||||
cursorContainer, cursorOffset, nodeAfterCursor;
|
|
||||||
moveRangeBoundariesUpTree( range, self._body );
|
moveRangeBoundariesUpTree( range, self._body );
|
||||||
cursorContainer = range.endContainer;
|
cursorContainer = range.endContainer;
|
||||||
cursorOffset = range.endOffset;
|
cursorOffset = range.endOffset;
|
||||||
|
|
Loading…
Reference in a new issue