Fossil SCM
Chat: disable pasting of text when then input field does NOT have focus and fix complete overwriting of input field when pasting and it DOES have focus. Whether or not we should paste to that field when it does not have focus is debatable and possibly violates the Principle of Least Surprise.
Commit
87ff8fe35796cc0a9ac8114a3ce3ed1ee268a4249d9056803a6109fd65354226
Parent
15bc20f29db3050…
1 file changed
+12
-2
+12
-2
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -64,12 +64,22 @@ | ||
| 64 | 64 | if(!item || !item.type) return; |
| 65 | 65 | //console.debug("pasted item =",item); |
| 66 | 66 | if('file'===item.kind){ |
| 67 | 67 | updateDropZoneContent(false/*clear prev state*/); |
| 68 | 68 | updateDropZoneContent(items[0].getAsFile()); |
| 69 | - }else if('string'===item.kind){ | |
| 70 | - item.getAsString((v)=>form.msg.value = v); | |
| 69 | + }else if(false && 'string'===item.kind){ | |
| 70 | + /* ----^^^^^ disabled for now: | |
| 71 | + | |
| 72 | + The intent here is that if form.msg is not active, populate | |
| 73 | + it with this text, but whether populating it from ctrl-v when | |
| 74 | + it does not have focus is a feature or a bug is debatable. | |
| 75 | + */ | |
| 76 | + if(document.activeElement !== form.msg){ | |
| 77 | + /* Overwrite input field if it DOES NOT have focus, | |
| 78 | + otherwise let it do its own paste handling. */ | |
| 79 | + item.getAsString((v)=>form.msg.value = v); | |
| 80 | + } | |
| 71 | 81 | } |
| 72 | 82 | }; |
| 73 | 83 | if(true){/* Add help button for drag/drop/paste zone */ |
| 74 | 84 | const help = D.div(); |
| 75 | 85 | form.file.parentNode.insertBefore(help, form.file); |
| 76 | 86 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -64,12 +64,22 @@ | |
| 64 | if(!item || !item.type) return; |
| 65 | //console.debug("pasted item =",item); |
| 66 | if('file'===item.kind){ |
| 67 | updateDropZoneContent(false/*clear prev state*/); |
| 68 | updateDropZoneContent(items[0].getAsFile()); |
| 69 | }else if('string'===item.kind){ |
| 70 | item.getAsString((v)=>form.msg.value = v); |
| 71 | } |
| 72 | }; |
| 73 | if(true){/* Add help button for drag/drop/paste zone */ |
| 74 | const help = D.div(); |
| 75 | form.file.parentNode.insertBefore(help, form.file); |
| 76 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -64,12 +64,22 @@ | |
| 64 | if(!item || !item.type) return; |
| 65 | //console.debug("pasted item =",item); |
| 66 | if('file'===item.kind){ |
| 67 | updateDropZoneContent(false/*clear prev state*/); |
| 68 | updateDropZoneContent(items[0].getAsFile()); |
| 69 | }else if(false && 'string'===item.kind){ |
| 70 | /* ----^^^^^ disabled for now: |
| 71 | |
| 72 | The intent here is that if form.msg is not active, populate |
| 73 | it with this text, but whether populating it from ctrl-v when |
| 74 | it does not have focus is a feature or a bug is debatable. |
| 75 | */ |
| 76 | if(document.activeElement !== form.msg){ |
| 77 | /* Overwrite input field if it DOES NOT have focus, |
| 78 | otherwise let it do its own paste handling. */ |
| 79 | item.getAsString((v)=>form.msg.value = v); |
| 80 | } |
| 81 | } |
| 82 | }; |
| 83 | if(true){/* Add help button for drag/drop/paste zone */ |
| 84 | const help = D.div(); |
| 85 | form.file.parentNode.insertBefore(help, form.file); |
| 86 |