0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Fix FF deleting everything on cut.

This commit is contained in:
Neil Jenkins 2011-11-03 17:05:18 +11:00
parent 0bdbef305a
commit 28c9ab10a9
4 changed files with 21 additions and 16 deletions

File diff suppressed because one or more lines are too long

View file

@ -900,7 +900,14 @@ document.addEventListener( 'DOMContentLoaded', function () {
return root;
};
// --- Paste ---
// --- Cut and Paste ---
doc.addEventListener( 'cut', function () {
// If all content removed, ensure div at start of body.
setTimeout( function () {
body.fixCursor();
}, 0 );
});
doc.addEventListener( 'paste', function () {
var range = getSelection(),

View file

@ -356,9 +356,14 @@ implement( Element, {
fixer, child;
if ( el.nodeName === 'BODY' ) {
if ( !el.firstChild ) {
if ( !( child = el.firstChild ) || child.nodeName === 'BR' ) {
fixer = doc.createElement( 'DIV' );
if ( child ) {
el.replaceChild( fixer, child );
}
else {
el.appendChild( fixer );
}
el = fixer;
fixer = null;
}

View file

@ -148,18 +148,11 @@ implement( Range, {
}
// Ensure body has a block-level element in it.
var doc = this.endContainer.ownerDocument,
body = doc.body,
bodyFirstChild = body.firstChild;
if ( !bodyFirstChild || bodyFirstChild.nodeName === 'BR' ) {
startBlock = doc.createElement( 'DIV' ).fixCursor();
if ( bodyFirstChild ) {
body.replaceChild( startBlock, bodyFirstChild );
}
else {
body.appendChild( startBlock );
}
this.selectNodeContents( startBlock );
var body = this.endContainer.ownerDocument.body,
child = body.firstChild;
if ( !child || child.nodeName === 'BR' ) {
body.fixCursor();
this.selectNodeContents( body.firstChild );
}
// Ensure valid range (must have only block or inline containers)