0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Make it possible to delete an <img> with display other than inline

Based on pull request #85 from dryoma.
This commit is contained in:
Neil Jenkins 2015-06-17 17:18:34 +07:00
parent a712b4f8e7
commit 09167c73e4
3 changed files with 40 additions and 4 deletions

View file

@ -1375,7 +1375,25 @@ var keyHandlers = {
// Otherwise, leave to browser but check afterwards whether it has
// left behind an empty inline tag.
else {
self.setSelection( range );
// 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
// inline.
var originalRange = range.cloneRange(),
cursorContainer, cursorOffset, nodeAfterCursor;
moveRangeBoundariesUpTree( range, self._body );
cursorContainer = range.endContainer;
cursorOffset = range.endOffset;
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
nodeAfterCursor = cursorContainer.childNodes[ cursorOffset ];
if ( nodeAfterCursor && nodeAfterCursor.nodeName === 'IMG' ) {
event.preventDefault();
detach( nodeAfterCursor );
moveRangeBoundariesDownTree( range );
afterDelete( self, range );
return;
}
}
self.setSelection( originalRange );
setTimeout( function () { afterDelete( self ); }, 0 );
}
},

File diff suppressed because one or more lines are too long

View file

@ -275,7 +275,25 @@ var keyHandlers = {
// Otherwise, leave to browser but check afterwards whether it has
// left behind an empty inline tag.
else {
self.setSelection( range );
// 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
// inline.
var originalRange = range.cloneRange(),
cursorContainer, cursorOffset, nodeAfterCursor;
moveRangeBoundariesUpTree( range, self._body );
cursorContainer = range.endContainer;
cursorOffset = range.endOffset;
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
nodeAfterCursor = cursorContainer.childNodes[ cursorOffset ];
if ( nodeAfterCursor && nodeAfterCursor.nodeName === 'IMG' ) {
event.preventDefault();
detach( nodeAfterCursor );
moveRangeBoundariesDownTree( range );
afterDelete( self, range );
return;
}
}
self.setSelection( originalRange );
setTimeout( function () { afterDelete( self ); }, 0 );
}
},