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

Insert table rather than image on paste from Excel

This commit is contained in:
Neil Jenkins 2019-02-20 16:06:04 +11:00
parent 2059c5a4ae
commit 43b2c6b0e1
3 changed files with 21 additions and 7 deletions

View file

@ -2346,6 +2346,7 @@ var onPaste = function ( event ) {
var items = clipboardData && clipboardData.items; var items = clipboardData && clipboardData.items;
var choosePlain = this.isShiftDown; var choosePlain = this.isShiftDown;
var fireDrop = false; var fireDrop = false;
var hasRTF = false;
var hasImage = false; var hasImage = false;
var plainItem = null; var plainItem = null;
var htmlItem = null; var htmlItem = null;
@ -2364,6 +2365,8 @@ var onPaste = function ( event ) {
htmlItem = item; htmlItem = item;
} else if ( type === 'text/plain' ) { } else if ( type === 'text/plain' ) {
plainItem = item; plainItem = item;
} else if ( type === 'text/rtf' ) {
hasRTF = true;
} else if ( /^image\/.*/.test( type ) ) { } else if ( /^image\/.*/.test( type ) ) {
hasImage = true; hasImage = true;
} }
@ -2372,9 +2375,13 @@ var onPaste = function ( event ) {
// Treat image paste as a drop of an image file. When you copy // Treat image paste as a drop of an image file. When you copy
// an image in Chrome/Firefox (at least), it copies the image data // an image in Chrome/Firefox (at least), it copies the image data
// but also an HTML version (referencing the original URL of the image) // but also an HTML version (referencing the original URL of the image)
// and a plain text version. So we check for image data first, only if // and a plain text version.
// none look for text/html. //
if ( hasImage ) { // However, when you copy in Excel, you get html, rtf, text, image;
// in this instance you want the html version! So let's try using
// the presence of text/rtf as an indicator to choose the html version
// over the image.
if ( hasImage && !( hasRTF && htmlItem ) ) {
event.preventDefault(); event.preventDefault();
this.fireEvent( 'dragover', { this.fireEvent( 'dragover', {
dataTransfer: clipboardData, dataTransfer: clipboardData,

File diff suppressed because one or more lines are too long

View file

@ -145,6 +145,7 @@ var onPaste = function ( event ) {
var items = clipboardData && clipboardData.items; var items = clipboardData && clipboardData.items;
var choosePlain = this.isShiftDown; var choosePlain = this.isShiftDown;
var fireDrop = false; var fireDrop = false;
var hasRTF = false;
var hasImage = false; var hasImage = false;
var plainItem = null; var plainItem = null;
var htmlItem = null; var htmlItem = null;
@ -163,6 +164,8 @@ var onPaste = function ( event ) {
htmlItem = item; htmlItem = item;
} else if ( type === 'text/plain' ) { } else if ( type === 'text/plain' ) {
plainItem = item; plainItem = item;
} else if ( type === 'text/rtf' ) {
hasRTF = true;
} else if ( /^image\/.*/.test( type ) ) { } else if ( /^image\/.*/.test( type ) ) {
hasImage = true; hasImage = true;
} }
@ -171,9 +174,13 @@ var onPaste = function ( event ) {
// Treat image paste as a drop of an image file. When you copy // Treat image paste as a drop of an image file. When you copy
// an image in Chrome/Firefox (at least), it copies the image data // an image in Chrome/Firefox (at least), it copies the image data
// but also an HTML version (referencing the original URL of the image) // but also an HTML version (referencing the original URL of the image)
// and a plain text version. So we check for image data first, only if // and a plain text version.
// none look for text/html. //
if ( hasImage ) { // However, when you copy in Excel, you get html, rtf, text, image;
// in this instance you want the html version! So let's try using
// the presence of text/rtf as an indicator to choose the html version
// over the image.
if ( hasImage && !( hasRTF && htmlItem ) ) {
event.preventDefault(); event.preventDefault();
this.fireEvent( 'dragover', { this.fireEvent( 'dragover', {
dataTransfer: clipboardData, dataTransfer: clipboardData,