Pasting into the composer with both image and text in the clipboard

(this was also a problem in the old one)

If you paste into the composer and the clipboard has data available in both an image and text format, they both appear:

![image|171x34](upload://sWXiVew6f5ZJK7SHcyYWgaQyWtV.png)col1	col2
A	B

imagecol1 col2
A B

It would be better if only the image appeared when a Paste action happened, and the text appeared when the Paste as plain text action happened.

The formats available for the clipboard data in this case (cells copied from libreoffice) are:

Formats: text/plain;charset=utf-8,text/plain;charset=UTF-8,UTF-8,UTF8_STRING,COMPOUND_TEXT,STRING,application/x-openoffice-embed-source-xml;windows_formatname="Star Embed Source (XML)",application/x-openoffice-objectdescriptor-xml;windows_formatname="Star Object Descriptor (XML)";classname="47BBB4CB-CE4C-4E80-a591-42d9ae74950f";typename="calc8";viewaspect="1";width="4516";height="904";posx="0";posy="0",application/x-openoffice-gdimetafile;windows_formatname="GDIMetaFile",application/x-openoffice-emf;windows_formatname="Image EMF",application/x-openoffice-wmf;windows_formatname="Image WMF",image/png,application/x-openoffice-bitmap;windows_formatname="Bitmap",PIXMAP,image/bmp,text/html,application/x-openoffice-sylk;windows_formatname="Sylk",application/x-openoffice-link;windows_formatname="Link",application/x-openoffice-dif;windows_formatname="DIF",text/richtext,MULTIPLE```
2 Likes

As in CTRL+V vs. CTRL+SHIFT+V?

2 Likes

Right, that or the muggle right-click and paste method :smiley:

Or maybe I’m using this keyboard:

2 Likes

What would be really great would be if the text data became the image’s alt text. In this case, the code would end up being:

![col1	col2
A	B](upload://sWXiVew6f5ZJK7SHcyYWgaQyWtV.png)
2 Likes

I think this is Excel (or clones) specific so I don’t view this as a priority. Can anyone list any other application that does this?

My search-fu is failing me but I remember a similar issue where you would paste an image into the composer and there would be both the image and the url of that image inserted.

3 Likes

What would be awesome here is if we check for a format that excel has and just format the results as a proper CommonMark table (cause it exists in the clipboard as xml), this would be so much magic and so much cool.

5 Likes

If you request the clipboard data as plain text you get probably the most useful thing for turning into a table:

image
:arrow_down:

'1\t3\n2\t4\n'

(the closest you have to XML is text/html and that’s a standalone page)

All of them? Very common to have the same object on the clipboard in multiple formats so different programs can use it in the way they see fit. e.g. copy an image in your browser (Right-Click, Copy) and you can retrieve it as any of: TIMESTAMP,TARGETS,SAVE_TARGETS,MULTIPLE,image/png,text/html,text/x-moz-url. That’s why sometimes you get the URL, sometimes you get the image itself depending on the application. Or an object embed.

As much fun as it would be to do something super nifty here, all I think this needs is “just paste the image” for now.

What other apps cause an error on paste though, specifically? Where two sets of data appear when you paste? I believe Excel and its clones are the only one.

I copy and paste tables from Excel all the time. With forumlas in Excel to turn columns into Markdown format. The always forget to copy to notepad before pastuing otherwise it will paste an image. Frustrating, if you post Excel content a lot.

1 Like

Right but it is quite specific to excel and clones, is my point.

1 Like

This seems to occur with Microsoft Word for Mac as well. Testing with Word on Windows shortly.

https://try.discourse.org/t/this-is-a-test-topic-copied-from-word-on-mac/884?u=jomaxro

Edit: This issue does not occur with Word on Windows.

5 Likes

This has come up a fair bit.

https://meta.discourse.org/search?q=Excel%20paste

Now that we have markdown table support it would be good to have excel paste in as a markdown table @vinothkannans I agree with that.

5 Likes

Don’t forget to put commas and quotes in the table data you’re copying, if it’s coming in as CSV. Proper CSV escaping is everybody’s job!

4 Likes

Some programs, Excel for instance, will use a tab-separated non-quotes format instead of CSV. This should be supported too.

2 Likes

https://answers.microsoft.com/en-us/mac/forum/macoffice2016-macword/word-2016-for-mac-problems-with-copypaste-of-text/c6bde085-9d36-4eaf-a73a-5dfd07e08976

@jomaxro I am unable to see the url you linked to try. I guess this is related to that problem?

That does not sound like the issue I encountered. The try topic is gone due to the daily reset. Here’re the steps I completed to cause the issue:

  1. Created a test document in Word for Mac. I used https://www.lipsum.com/ to generate 5 paragraphs of text. I did not include any formatting or images in the document.
  2. I copied the entirety of the document using Command + A and Command + C
  3. I created a new topic on Discourse, and pasted the content in using Command + V

The text was pasted into the composer. In addition, an “image” of the text was also uploaded.

PR created to prevent duplicate pasting if both image and text available in clipboard.

While copy paste from Word, Excel, etc., composer receives multiple inputs with data types like text/plain, text/html, text/rtf and file image/png from clipboard. (for the same copied content)

By default text/plain getting used. Instead if we use text/html by converting it to markdown then not only tables we can support more HTML tags while copy paste.

Else I can convert plain text to markdown table for now.

3 Likes

Only when both paste types are detected, then we should skip one of them,
the image one. We should not prioritize image pastes unless there is no
other way to do this.

As per Jeff’s advice I am doing it in other way. The images will be skipped if clipboard have file data.

2 Likes

The original example is excel and excel-clones. I can’t think of any reason, ever, that you would want a picture of a table of numbers rather than … an actual table of numbers. :wink:

5 Likes