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

Cleanup HTML after drop

clean up the html after a drop and add links
This commit is contained in:
Andy Kauffman 2016-05-31 15:04:35 -04:00
parent 9dcc4fb79f
commit 09cb6045ef
3 changed files with 38 additions and 6 deletions

View file

@ -2243,7 +2243,7 @@ var onPaste = function ( event ) {
}, 0 );
};
// On Windows you can drag an drop text. We can't handle this ourselves, because
// On Windows and Macs you can drag an drop text. We can't handle this ourselves, because
// as far as I can see, there's no way to get the drop insertion point. So just
// save an undo state and hope for the best.
var onDrop = function ( event ) {
@ -2254,17 +2254,33 @@ var onDrop = function ( event ) {
while ( l-- ) {
switch ( types[l] ) {
case 'text/plain':
case 'Text': // IE Specific
hasPlain = true;
break;
case 'text/html':
hasHTML = true;
break;
default:
return;
break;
}
}
if ( hasHTML || hasPlain ) {
var range = this.getSelection();
this.saveUndoState();
this.setSelection( range );
// Wait until the drop occurs then clean it. Ideally we would only do this
// for HTML drops, but some browsers send HTML as text/plain.
var self = this;
setTimeout( function () {
try {
cleanTree( self._root );
addLinks( self._root, self._root, self );
} catch ( error ) {
self.didError( error );
}
}, 0 );
}
};

File diff suppressed because one or more lines are too long

View file

@ -207,7 +207,7 @@ var onPaste = function ( event ) {
}, 0 );
};
// On Windows you can drag an drop text. We can't handle this ourselves, because
// On Windows and Macs you can drag an drop text. We can't handle this ourselves, because
// as far as I can see, there's no way to get the drop insertion point. So just
// save an undo state and hope for the best.
var onDrop = function ( event ) {
@ -218,16 +218,32 @@ var onDrop = function ( event ) {
while ( l-- ) {
switch ( types[l] ) {
case 'text/plain':
case 'Text': // IE Specific
hasPlain = true;
break;
case 'text/html':
hasHTML = true;
break;
default:
return;
break;
}
}
if ( hasHTML || hasPlain ) {
var range = this.getSelection();
this.saveUndoState();
this.setSelection( range );
// Wait until the drop occurs then clean it. Ideally we would only do this
// for HTML drops, but some browsers send HTML as text/plain.
var self = this;
setTimeout( function () {
try {
cleanTree( self._root );
addLinks( self._root, self._root, self );
} catch ( error ) {
self.didError( error );
}
}, 0 );
}
};