0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

If all text in inline tag deleted, remove tag.

This commit is contained in:
Neil Jenkins 2012-07-02 12:41:38 +10:00
parent 819ddb296e
commit e4b5ea6ee8
5 changed files with 84 additions and 44 deletions

File diff suppressed because one or more lines are too long

View file

@ -1288,6 +1288,38 @@
};
};
// If you delete the content inside a span with a font styling, Webkit will
// replace it with a <font> tag (!). If you delete all the text inside a
// link in Opera, it won't delete the link. Let's make things consistent. If
// you delete all text inside an inline tag, remove the inline tag.
var afterDelete = function () {
var range = getSelection(),
node = range.startContainer,
parent;
node = node.nodeType === TEXT_NODE ?
node.length ? null : node.parentNode :
node.isInline() && !node.textContent ? node : null;
// If focussed in empty inline element
if ( node ) {
do {
parent = node.parentNode;
} while ( parent.isInline() &&
!parent.textContent && ( node = parent ) );
range.setStart( parent,
indexOf.call( parent.childNodes, node ) );
range.collapse( true );
parent.removeChild( node );
if ( !parent.isBlock() ) {
parent = parent.getPreviousBlock();
}
parent.fixCursor();
range.moveBoundariesDownTree();
setSelection( range );
updatePath( range );
}
};
var keyHandlers = {
enter: function ( event ) {
// We handle this ourselves
@ -1469,7 +1501,11 @@
updatePath( range, true );
}
}
// All other cases can be safely left to the browser (I hope!).
// Otherwise, leave to browser but check afterwards whether it has
// left behind an empty inline tag.
else {
setTimeout( afterDelete, 0 );
}
},
'delete': function ( event ) {
var range = getSelection();
@ -1501,7 +1537,11 @@
updatePath( range, true );
}
}
// All other cases can be safely left to the browser (I hope!).
// Otherwise, leave to browser but check afterwards whether it has
// left behind an empty inline tag.
else {
setTimeout( afterDelete, 0 );
}
},
space: function () {
var range = getSelection();

View file

@ -31,7 +31,7 @@ var every = function ( nodeList, fn ) {
var $False = function () { return false; };
var $True = function () { return true; };
var inlineNodeNames = /^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/;
var inlineNodeNames = /^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/;
var leafNodeNames = {
BR: 1,