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:
parent
0bdbef305a
commit
28c9ab10a9
4 changed files with 21 additions and 16 deletions
File diff suppressed because one or more lines are too long
|
@ -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(),
|
||||
|
|
|
@ -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' );
|
||||
el.appendChild( fixer );
|
||||
if ( child ) {
|
||||
el.replaceChild( fixer, child );
|
||||
}
|
||||
else {
|
||||
el.appendChild( fixer );
|
||||
}
|
||||
el = fixer;
|
||||
fixer = null;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue