mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -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:
parent
a712b4f8e7
commit
09167c73e4
3 changed files with 40 additions and 4 deletions
|
@ -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
|
@ -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 );
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue