Fossil SCM
Chat clipboard paste: pasted text, regardless of event target, now goes to the input field and pasted images, regardless of the event target, now go into the image-submit slot.
Commit
02fa19aa996d44be5732ac36434d256becb2ceb29a8b3bf45416b2c91ede3505
Parent
8f736e84565d995…
1 file changed
+15
-8
+15
-8
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -28,18 +28,25 @@ | ||
| 28 | 28 | }); |
| 29 | 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | 30 | paste images here (silently ignore non-image data), or change the |
| 31 | 31 | related code to support non-image pasting/posting. */ |
| 32 | 32 | document.onpaste = function(event){ |
| 33 | - if(form.msg === event.target) return; | |
| 34 | - const items = event.clipboardData.items; | |
| 35 | - ImagePasteState.blob = items[0].getAsFile(); | |
| 36 | - const reader = new FileReader(); | |
| 37 | - reader.onload = function(event){ | |
| 38 | - ImagePasteState.imgTag.setAttribute('src', event.target.result); | |
| 39 | - }; | |
| 40 | - reader.readAsDataURL(ImagePasteState.blob); | |
| 33 | + const items = event.clipboardData.items, | |
| 34 | + item = items[0]; | |
| 35 | + if(!item || !item.type) return; | |
| 36 | + //console.debug("pasted item =",item); | |
| 37 | + if('file'===item.kind && item.type.startsWith("image/")){ | |
| 38 | + ImagePasteState.blob = items[0].getAsFile(); | |
| 39 | + //console.debug("pasted blob =",ImagePasteState.blob); | |
| 40 | + const reader = new FileReader(); | |
| 41 | + reader.onload = function(event){ | |
| 42 | + ImagePasteState.imgTag.setAttribute('src', event.target.result); | |
| 43 | + }; | |
| 44 | + reader.readAsDataURL(ImagePasteState.blob); | |
| 45 | + }else if('string'===item.kind){ | |
| 46 | + item.getAsString((v)=>form.msg.value = v); | |
| 47 | + } | |
| 41 | 48 | }; |
| 42 | 49 | /* Injects element e as a new row in the chat, at the top of the list */ |
| 43 | 50 | const injectMessage = function f(e){ |
| 44 | 51 | if(!f.injectPoint){ |
| 45 | 52 | f.injectPoint = document.querySelector('#message-inject-point'); |
| 46 | 53 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -28,18 +28,25 @@ | |
| 28 | }); |
| 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | paste images here (silently ignore non-image data), or change the |
| 31 | related code to support non-image pasting/posting. */ |
| 32 | document.onpaste = function(event){ |
| 33 | if(form.msg === event.target) return; |
| 34 | const items = event.clipboardData.items; |
| 35 | ImagePasteState.blob = items[0].getAsFile(); |
| 36 | const reader = new FileReader(); |
| 37 | reader.onload = function(event){ |
| 38 | ImagePasteState.imgTag.setAttribute('src', event.target.result); |
| 39 | }; |
| 40 | reader.readAsDataURL(ImagePasteState.blob); |
| 41 | }; |
| 42 | /* Injects element e as a new row in the chat, at the top of the list */ |
| 43 | const injectMessage = function f(e){ |
| 44 | if(!f.injectPoint){ |
| 45 | f.injectPoint = document.querySelector('#message-inject-point'); |
| 46 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -28,18 +28,25 @@ | |
| 28 | }); |
| 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | paste images here (silently ignore non-image data), or change the |
| 31 | related code to support non-image pasting/posting. */ |
| 32 | document.onpaste = function(event){ |
| 33 | const items = event.clipboardData.items, |
| 34 | item = items[0]; |
| 35 | if(!item || !item.type) return; |
| 36 | //console.debug("pasted item =",item); |
| 37 | if('file'===item.kind && item.type.startsWith("image/")){ |
| 38 | ImagePasteState.blob = items[0].getAsFile(); |
| 39 | //console.debug("pasted blob =",ImagePasteState.blob); |
| 40 | const reader = new FileReader(); |
| 41 | reader.onload = function(event){ |
| 42 | ImagePasteState.imgTag.setAttribute('src', event.target.result); |
| 43 | }; |
| 44 | reader.readAsDataURL(ImagePasteState.blob); |
| 45 | }else if('string'===item.kind){ |
| 46 | item.getAsString((v)=>form.msg.value = v); |
| 47 | } |
| 48 | }; |
| 49 | /* Injects element e as a new row in the chat, at the top of the list */ |
| 50 | const injectMessage = function f(e){ |
| 51 | if(!f.injectPoint){ |
| 52 | f.injectPoint = document.querySelector('#message-inject-point'); |
| 53 |