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; 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 () { doc.addEventListener( 'paste', function () {
var range = getSelection(), var range = getSelection(),

View file

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

View file

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