SOLVED

Why does Teams always strip indentation when pasting text?

%3CLINGO-SUB%20id%3D%22lingo-sub-2349812%22%20slang%3D%22en-US%22%3EWhy%20does%20Teams%20always%20strip%20indentation%20when%20pasting%20text%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2349812%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%20fairly%20common%20to%20want%20to%20post%20code%20in%20teams%20(without%20using%20the%20special%20formatting%20for%20code%20snippets).%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20markdown%20like%20syntax%20for%20code%20works%20pretty%20well%20when%20typing%20code%20and%20it%20preserves%20indentation.%20But%20when%20you%20past%20XML%20or%20JSON%20all%20the%20indentation%20is%20removed.%20Why%3F%3CBR%20%2F%3E%3CBR%20%2F%3EHere's%20an%20example%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22my-kl_0-1620853640676.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280348iA5C8917E5FB6D15B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22my-kl_0-1620853640676.png%22%20alt%3D%22my-kl_0-1620853640676.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3EThat%20XML%20was%20indented%20in%20the%20source.%20But%20whenever%20we%20paste%20JSON%20or%20XML%20we%20lose%20indentation.%20Unless%20we%20take%20the%20extra%20effort%20to%20use%20a%20code%20snippet.%20Or%20manually%20type%20it%20for%20small%20examples.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2349812%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EUser%20Interface%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2355254%22%20slang%3D%22en-US%22%3ERe%3A%20Why%20does%20Teams%20always%20strip%20indentation%20when%20pasting%20text%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2355254%22%20slang%3D%22en-US%22%3EThis%20is%20on%20macOS%2C%20colleagues%20tell%20me%20they%20don't%20have%20an%20issue%20on%20Windows.%3C%2FLINGO-BODY%3E
Occasional Contributor

It's fairly common to want to post code in teams (without using the special formatting for code snippets).

The markdown like syntax for code works pretty well when typing code and it preserves indentation. But when you past XML or JSON all the indentation is removed. Why?

Here's an example:

my-kl_0-1620853640676.png
That XML was indented in the source. But whenever we paste JSON or XML we lose indentation. Unless we take the extra effort to use a code snippet. Or manually type it for small examples.

5 Replies
This is on macOS, colleagues tell me they don't have an issue on Windows.
Ok some more sleuthing:

If I copy from Visual Studio Code and paste into Teams (on macOS) this problem happens.

If I copy from TextEdit or Visual Studio and paste into Teams, the indentation is fine.

So this is weird interaction between Teams, the clipboard and Visual Studio Code.

But, I can copy from Visual Studio Code into TextEdit and everything is fine. Then I can copy from TextEdit and paste into Teams and everything is fine.

Anyone have a firm understanding of how the clipboard works and what app might be working incorrectly? Seems perhaps Teams is confused by meta data from Visual Studio Code?
Using this website I was able to examine the clipboard data from TextEdit and Visual Studio code.

The text/plain entries look identical, but the text/html entries are radically different. That seems to be a clue.
best response confirmed by ThereseSolimeno (Microsoft)
Solution

@my-kl 

So I got to the heart of the matter. I used the Clipboard Inspector to inspect the contents of clipboard when copying the same text from two different apps. Both have two entries. One of the entries is text/html and one is text/plain. The text/plain as you might guess is identical. The html is quite different. I then copied the html and rendered.

This is what I see from TextEdit

 

my-kl_1-1621015953588.png

This is what I see from Visual Studio Code

 

my-kl_0-1621015929280.png

So this would appear to be an issue with my environment in Visual Studio Code (or even a defect in Code, I"m not sure)

 

This can probably be closed. I've added details to an already opened issue on GitHub: https://github.com/microsoft/vscode/issues/122050#issuecomment-841814182