Clipboard Image

Both text and image data available from clipboard - Clipboard Image

Both text and image data available from clipboard

by EA117 » Tue Mar 12, 2019 2:53 pm

Observed an unanticipated result today: When pasting a couple rows out of Excel (Microsoft Office 365 version 1902 build 11328.20146) into Chrome 72.0.3626.121 on Windows 10 1809 x64 build 17763.316, both a text representation of the data and an image representation of the data were inserted into the post in response to the same single Paste event.

So Excel had generated an image representation of the cells, and also a text representation of the cell data, and both were available in the clipboard. The edit box itself retrieved the text version during the Paste event, and the Clipboard Image extension ended up seeing the same Paste event and retrieved the image version.

Haven't gone back to re-read the Javascript API description of the clipboard event handling, but I'm guessing we don't have the opportunity to say "this Paste event has already been handled". And maybe we'll need to resort to "if text/plain is also available, don't" to the Clipboard Image logic. (Since the edit control is going to retrieve the text/plain version, and we can't stop it, nor do we really want to.)

I'd say "that's handy to have the option to retrieve the image version instead" (since in this Excel case, that does solve some formatting issues in absence of built-in table BBCodes), but in reality I think "allow both to be inserted" will be more annoying than helpful. For example, the only reason I noticed the issue before posting was because I still have your modification to "insert image inline" (unlike the released 1.0 version), and so I was seeing the inline attachment text in addition to the Excel text. If someone is pasting a bunch of data into their post, they're going to have several or several dozen attachments to delete, which they may or may not even notice until after they've posted.
User avatar
EA117
Registered User
Posts: 512
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Both text and image data available from clipboard

by Senky » Tue Mar 12, 2019 3:07 pm

This sounds like a very rare case and as you already pointed out, there are two desired outputs. One may expect text, another image to keep formatting. Not really sure how to handle this as any way I go will result in complains about expecting another way to be defaulted. So maybe the current behaviour IS the best way to handle it after all. Everyone has to delete some parts of the text/attachments, but at least everyone ends up having what he/she wanted...
Senky
Extension Customisations
Extension Customisations
Posts: 2010
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Both text and image data available from clipboard

by EA117 » Wed Mar 13, 2019 2:12 am

Fair enough. Thanks for having considered the scenario.

Definitely what Excel (or any application that would render/offer both text and image representation of the same data) must be assuming is that the user would have a "Paste Special..." menu option (as many Windows applications do) that lets them choose which of multiple formats of data from the clipboard they want, if they weren't happy with the format that is selected by default.

Note that in the Chrome platform I was describing, right-clicking the edit box offers the default "Paste" option, but also offers "Paste as plain text". And selecting "Paste as plain text" apparently doesn't cause any event in the Javascript API, because I don't get the image that way. Firefox and Edge on the same platform only offers "Paste" in any menu, and always gets the image in addition to text.

The extension is simple and elegant as it is, so it's very understandable that there will be a high if not impossible bar to ever "add UI elements" to the implementation. But that's the main idea that comes to mind for "how would it ever be done": If "text/plain" in addition to one or more image formats are enumerated, present a an ajax pop-up that allows the user to decline getting the image paste in addition to (presumably) the text paste that the browser's edit box is doing on its own. Otherwise, when no text format exists in addition to the image format, the behavior remains as it is today without any UI.
User avatar
EA117
Registered User
Posts: 512
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Both text and image data available from clipboard

by Senky » Wed Mar 13, 2019 9:20 am

EA117 wrote:But that's the main idea that comes to mind for "how would it ever be done": If "text/plain" in addition to one or more image formats are enumerated, present a an ajax pop-up that allows the user to decline getting the image paste in addition to (presumably) the text paste that the browser's edit box is doing on its own. Otherwise, when no text format exists in addition to the image format, the behavior remains as it is today without any UI.
That really sounds like a great solution! I will take a look at it.
Senky
Extension Customisations
Extension Customisations
Posts: 2010
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Both text and image data available from clipboard

by EA117 » Wed Apr 10, 2019 8:33 pm

The 2.0.0.0 implementation of this is nice. And appreciate having the insert-inline default back, too.

The position of where the current prompting occurs is okay, and I like the "button" style of it. My only concern would be that nothing "forces" your attention to there, nor that this portion of the screen will even be visible at that moment. i.e. By definition, you're typing with your caret somewhere in the edit box, and initiating a paste event. Depending on your window size and position, it could very legitimately look like "nothing happened", even though what's happening is this prompting is occurring off-screen.

Is there a way to put an anchor tag in the display <div>, and then make the viewport scroll to where that anchor is located as part of displayPopUp? Just to be sure "where" the prompting occurs is also visible at the time we're expecting them to notice & respond to the prompting.

Or the alternative -- and perhaps what I defaulted to assuming, since phpBB uses it elsewhere -- would be to make a more literal "pop-up" in the middle of whatever viewport the user is currently looking at. i.e. A CSS-based modal, similar to the pop-ups that phpBB puts up when you delete cookies, or "mark all topics read", etc., which are displayed and dismissed without leaving the current page.

I'm not sure if phpBB provides any existing framework that could be leveraged to re-use whatever heavy lifting they're already doing for presenting those pop-ups. I had tried to follow where that code was a while back for this question, but didn't get there quickly enough and gave up.
User avatar
EA117
Registered User
Posts: 512
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Both text and image data available from clipboard

by Senky » Fri Apr 12, 2019 12:48 pm

Great idea! I already implemented this here:
https://github.com/senky/phpbb-ext-clip ... 68ba0bda66
expect it in a new version.
Senky
Extension Customisations
Extension Customisations
Posts: 2010
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Both text and image data available from clipboard

by EA117 » Mon Apr 15, 2019 1:18 pm

Senky wrote:I already implemented this here:
It's been working great for me. Windows is the only platform I could test the pop-up display on. I'm not sure what other platform scenario would create the multiple clipboard format condition for testing. Thanks again.
User avatar
EA117
Registered User
Posts: 512
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Both text and image data available from clipboard

by Senky » Mon Apr 15, 2019 6:17 pm

EA117 wrote:I'm not sure what other platform scenario would create the multiple clipboard format condition for testing. Thanks again.
I tested it using MS Excel on mac, works like a charm.
Senky
Extension Customisations
Extension Customisations
Posts: 2010
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact: