0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Workaround clipboard having blank text/html version.

This commit is contained in:
Neil Jenkins 2015-07-14 12:59:27 -07:00
parent 667b5e8e7b
commit fdcef5fc8e
3 changed files with 35 additions and 29 deletions

View file

@ -1977,7 +1977,7 @@ var onPaste = function ( event ) {
hasImage = false,
plainItem = null,
self = this,
l, item, type;
l, item, type, data;
// Current HTML5 Clipboard interface
// ---------------------------------
@ -2030,21 +2030,24 @@ var onPaste = function ( event ) {
// Old interface
// -------------
if ( clipboardData ) {
if ( indexOf.call( clipboardData.types, 'text/html' ) > -1 ) {
event.preventDefault();
this.insertHTML( clipboardData.getData( 'text/html' ), true );
return;
}
// Safari (and indeed many other OS X apps) copies stuff as text/rtf
// rather than text/html; even from a webpage in Safari. The only way
// to get an HTML version is to fallback to letting the browser insert
// the content. *Sigh*.
else if ( indexOf.call( clipboardData.types, 'text/rtf' ) === -1 ) {
event.preventDefault();
// Safari (and indeed many other OS X apps) copies stuff as text/rtf
// rather than text/html; even from a webpage in Safari. The only way
// to get an HTML version is to fallback to letting the browser insert
// the content. *Sigh*.
if ( clipboardData && (
indexOf.call( clipboardData.types, 'text/html' ) > -1 ||
indexOf.call( clipboardData.types, 'text/rtf' ) === -1 ) ) {
event.preventDefault();
// Abiword on Linux copies a plain text and html version, but the HTML
// version is the empty string! So always try to get HTML, but if none,
// insert plain text instead.
data = clipboardData.getData( 'text/html' );
if ( data ) {
this.insertHTML( data, true );
} else {
this.insertPlainText( clipboardData.getData( 'text/plain' ), true );
return;
}
return;
}
// No interface :(

File diff suppressed because one or more lines are too long

View file

@ -24,7 +24,7 @@ var onPaste = function ( event ) {
hasImage = false,
plainItem = null,
self = this,
l, item, type;
l, item, type, data;
// Current HTML5 Clipboard interface
// ---------------------------------
@ -77,21 +77,24 @@ var onPaste = function ( event ) {
// Old interface
// -------------
if ( clipboardData ) {
if ( indexOf.call( clipboardData.types, 'text/html' ) > -1 ) {
event.preventDefault();
this.insertHTML( clipboardData.getData( 'text/html' ), true );
return;
}
// Safari (and indeed many other OS X apps) copies stuff as text/rtf
// rather than text/html; even from a webpage in Safari. The only way
// to get an HTML version is to fallback to letting the browser insert
// the content. *Sigh*.
else if ( indexOf.call( clipboardData.types, 'text/rtf' ) === -1 ) {
event.preventDefault();
// Safari (and indeed many other OS X apps) copies stuff as text/rtf
// rather than text/html; even from a webpage in Safari. The only way
// to get an HTML version is to fallback to letting the browser insert
// the content. *Sigh*.
if ( clipboardData && (
indexOf.call( clipboardData.types, 'text/html' ) > -1 ||
indexOf.call( clipboardData.types, 'text/rtf' ) === -1 ) ) {
event.preventDefault();
// Abiword on Linux copies a plain text and html version, but the HTML
// version is the empty string! So always try to get HTML, but if none,
// insert plain text instead.
data = clipboardData.getData( 'text/html' );
if ( data ) {
this.insertHTML( data, true );
} else {
this.insertPlainText( clipboardData.getData( 'text/plain' ), true );
return;
}
return;
}
// No interface :(