@@ -39,11 +39,16 @@ export const useAttachments = (enableLoadURLs: boolean) => {
39
39
40
40
41
41
const attachAppendDataTransfer = React . useCallback ( ( dt : DataTransfer , method : AttachmentSourceOriginDTO , attachText : boolean ) : 'as_files' | 'as_url' | 'as_text' | false => {
42
+
43
+ // https://github.com/enricoros/big-AGI/issues/286
44
+ const textHtml = dt . getData ( 'text/html' ) || '' ;
45
+ const heuristicsIsExcel = textHtml . includes ( '"urn:schemas-microsoft-com:office:excel"' ) ;
46
+
42
47
if ( ATTACHMENTS_DEBUG )
43
- console . log ( 'attachAppendDataTransfer' , dt . types , dt . files ) ;
48
+ console . log ( 'attachAppendDataTransfer' , dt . types , dt . items , dt . files , textHtml ) ;
44
49
45
50
// attach File(s)
46
- if ( dt . files . length >= 1 ) {
51
+ if ( dt . files . length >= 1 && ! heuristicsIsExcel /* special case: ignore images from Microsoft Office pastes (prioritize the HTML paste) */ ) {
47
52
// rename files from a common prefix, to better relate them (if the transfer contains a list of paths)
48
53
let overrideFileNames : string [ ] = [ ] ;
49
54
if ( dt . types . includes ( 'text/plain' ) ) {
@@ -77,7 +82,6 @@ export const useAttachments = (enableLoadURLs: boolean) => {
77
82
}
78
83
79
84
// attach as Text/Html (further conversion, e.g. to markdown is done later)
80
- const textHtml = dt . getData ( 'text/html' ) || '' ;
81
85
if ( attachText && ( textHtml || textPlain ) ) {
82
86
void createAttachment ( {
83
87
media : 'text' , method, textPlain, textHtml,
@@ -109,16 +113,20 @@ export const useAttachments = (enableLoadURLs: boolean) => {
109
113
return ;
110
114
}
111
115
112
- if ( ATTACHMENTS_DEBUG )
113
- console . log ( 'attachAppendClipboardItems' , clipboardItems ) ;
114
-
115
- // loop on all the possible attachments
116
+ // loop on all the clipboard items
116
117
for ( const clipboardItem of clipboardItems ) {
117
118
119
+ // https://github.com/enricoros/big-AGI/issues/286
120
+ const textHtml = clipboardItem . types . includes ( 'text/html' ) ? await clipboardItem . getType ( 'text/html' ) . then ( blob => blob . text ( ) ) : '' ;
121
+ const heuristicsIsExcel = textHtml . startsWith ( '<table ' ) ;
122
+
123
+ if ( ATTACHMENTS_DEBUG )
124
+ console . log ( ' - attachAppendClipboardItems.item:' , clipboardItem , textHtml , heuristicsIsExcel ) ;
125
+
118
126
// attach as image
119
127
let imageAttached = false ;
120
128
for ( const mimeType of clipboardItem . types ) {
121
- if ( mimeType . startsWith ( 'image/' ) ) {
129
+ if ( mimeType . startsWith ( 'image/' ) && ! heuristicsIsExcel ) {
122
130
try {
123
131
const imageBlob = await clipboardItem . getType ( mimeType ) ;
124
132
const imageName = mimeType . replace ( 'image/' , 'clipboard.' ) . replaceAll ( '/' , '.' ) || 'clipboard.png' ;
@@ -148,7 +156,6 @@ export const useAttachments = (enableLoadURLs: boolean) => {
148
156
}
149
157
150
158
// attach as Text
151
- const textHtml = clipboardItem . types . includes ( 'text/html' ) ? await clipboardItem . getType ( 'text/html' ) . then ( blob => blob . text ( ) ) : '' ;
152
159
if ( textHtml || textPlain ) {
153
160
void createAttachment ( {
154
161
media : 'text' , method : 'clipboard-read' , textPlain, textHtml,
0 commit comments