Fossil SCM
Move the 'image.png' filename workaround for pasted images to avoid that attaching via file selection or drag/drop does not trigger the workaround. Remove stray debug output.
Commit
5fcc0dd3933baae5fb0dd68a62ad66c9b5921f8f0c38098a764996d8c0c7fe5b
Parent
69f1fe3ece563ff…
1 file changed
+7
-10
+7
-10
| --- src/fossil.attach.js | ||
| +++ src/fossil.attach.js | ||
| @@ -296,10 +296,17 @@ | ||
| 296 | 296 | }); |
| 297 | 297 | const pasteImage = (event, item)=>{ |
| 298 | 298 | if( item.type.indexOf('image') === 0 ) { |
| 299 | 299 | event.preventDefault(); |
| 300 | 300 | const blob = item.getAsFile(); |
| 301 | + if( blob.name === 'image.png' ){ | |
| 302 | + /* Workaround to attempt to avoid name collisions when pasting | |
| 303 | + multiple images. We cannot, at this level, unambiguously | |
| 304 | + distinguish a ctrl-v of bitmap data vs a ctrl-v of an image | |
| 305 | + file copied via a desktop file manager. */ | |
| 306 | + rowObj.overrideName = `pasted-image-${Date.now()}.png`; | |
| 307 | + } | |
| 301 | 308 | this.#injestBlob(rowObj, blob); |
| 302 | 309 | return true; |
| 303 | 310 | } |
| 304 | 311 | return false; |
| 305 | 312 | }; |
| @@ -376,17 +383,10 @@ | ||
| 376 | 383 | } |
| 377 | 384 | } |
| 378 | 385 | |
| 379 | 386 | #injestBlob(rowObj, file){ |
| 380 | 387 | if( !file ) return; |
| 381 | - if( file.name === 'image.png' ){ | |
| 382 | - /* Workaround to attempt to avoid name collisions when pasting | |
| 383 | - multiple images. We cannot, at this level, unambiguously | |
| 384 | - distinguish a ctrl-v of bitmap data vs a ctrl-v of an image | |
| 385 | - file copied via a desktop file manager. */ | |
| 386 | - rowObj.overrideName = `pasted-image-${Date.now()}.png`; | |
| 387 | - } | |
| 388 | 388 | const old = this.#rowMatchingName(file.name); |
| 389 | 389 | if( old && rowObj !== old ){ |
| 390 | 390 | /* |
| 391 | 391 | Fossil attachments treat the name as a unique-per-target |
| 392 | 392 | key, with the newest one being the primary. If a name is |
| @@ -399,15 +399,12 @@ | ||
| 399 | 399 | */ |
| 400 | 400 | /* recycle `old` instead to avoid UI flicker. */ |
| 401 | 401 | this.#rowError(old); |
| 402 | 402 | this.#removeRow(rowObj); |
| 403 | 403 | rowObj.e = old.e; |
| 404 | - //if( rowObj.e.eDesc ) rowObj.e.eDesc.value = ''; | |
| 405 | 404 | } |
| 406 | - console.warn("rowObj, old",rowObj, old); | |
| 407 | 405 | if( rowObj.overrideName ){ |
| 408 | - console.warn("Renaming file to",rowObj.overrideName); | |
| 409 | 406 | file = new File([file], rowObj.overrideName, {type: file.type}); |
| 410 | 407 | rowObj.overrideName = undefined; |
| 411 | 408 | } |
| 412 | 409 | |
| 413 | 410 | let szLbl; |
| 414 | 411 |
| --- src/fossil.attach.js | |
| +++ src/fossil.attach.js | |
| @@ -296,10 +296,17 @@ | |
| 296 | }); |
| 297 | const pasteImage = (event, item)=>{ |
| 298 | if( item.type.indexOf('image') === 0 ) { |
| 299 | event.preventDefault(); |
| 300 | const blob = item.getAsFile(); |
| 301 | this.#injestBlob(rowObj, blob); |
| 302 | return true; |
| 303 | } |
| 304 | return false; |
| 305 | }; |
| @@ -376,17 +383,10 @@ | |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | #injestBlob(rowObj, file){ |
| 380 | if( !file ) return; |
| 381 | if( file.name === 'image.png' ){ |
| 382 | /* Workaround to attempt to avoid name collisions when pasting |
| 383 | multiple images. We cannot, at this level, unambiguously |
| 384 | distinguish a ctrl-v of bitmap data vs a ctrl-v of an image |
| 385 | file copied via a desktop file manager. */ |
| 386 | rowObj.overrideName = `pasted-image-${Date.now()}.png`; |
| 387 | } |
| 388 | const old = this.#rowMatchingName(file.name); |
| 389 | if( old && rowObj !== old ){ |
| 390 | /* |
| 391 | Fossil attachments treat the name as a unique-per-target |
| 392 | key, with the newest one being the primary. If a name is |
| @@ -399,15 +399,12 @@ | |
| 399 | */ |
| 400 | /* recycle `old` instead to avoid UI flicker. */ |
| 401 | this.#rowError(old); |
| 402 | this.#removeRow(rowObj); |
| 403 | rowObj.e = old.e; |
| 404 | //if( rowObj.e.eDesc ) rowObj.e.eDesc.value = ''; |
| 405 | } |
| 406 | console.warn("rowObj, old",rowObj, old); |
| 407 | if( rowObj.overrideName ){ |
| 408 | console.warn("Renaming file to",rowObj.overrideName); |
| 409 | file = new File([file], rowObj.overrideName, {type: file.type}); |
| 410 | rowObj.overrideName = undefined; |
| 411 | } |
| 412 | |
| 413 | let szLbl; |
| 414 |
| --- src/fossil.attach.js | |
| +++ src/fossil.attach.js | |
| @@ -296,10 +296,17 @@ | |
| 296 | }); |
| 297 | const pasteImage = (event, item)=>{ |
| 298 | if( item.type.indexOf('image') === 0 ) { |
| 299 | event.preventDefault(); |
| 300 | const blob = item.getAsFile(); |
| 301 | if( blob.name === 'image.png' ){ |
| 302 | /* Workaround to attempt to avoid name collisions when pasting |
| 303 | multiple images. We cannot, at this level, unambiguously |
| 304 | distinguish a ctrl-v of bitmap data vs a ctrl-v of an image |
| 305 | file copied via a desktop file manager. */ |
| 306 | rowObj.overrideName = `pasted-image-${Date.now()}.png`; |
| 307 | } |
| 308 | this.#injestBlob(rowObj, blob); |
| 309 | return true; |
| 310 | } |
| 311 | return false; |
| 312 | }; |
| @@ -376,17 +383,10 @@ | |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | #injestBlob(rowObj, file){ |
| 387 | if( !file ) return; |
| 388 | const old = this.#rowMatchingName(file.name); |
| 389 | if( old && rowObj !== old ){ |
| 390 | /* |
| 391 | Fossil attachments treat the name as a unique-per-target |
| 392 | key, with the newest one being the primary. If a name is |
| @@ -399,15 +399,12 @@ | |
| 399 | */ |
| 400 | /* recycle `old` instead to avoid UI flicker. */ |
| 401 | this.#rowError(old); |
| 402 | this.#removeRow(rowObj); |
| 403 | rowObj.e = old.e; |
| 404 | } |
| 405 | if( rowObj.overrideName ){ |
| 406 | file = new File([file], rowObj.overrideName, {type: file.type}); |
| 407 | rowObj.overrideName = undefined; |
| 408 | } |
| 409 | |
| 410 | let szLbl; |
| 411 |