# Indentation is gone when pasting from VSCode

When I copy some code from the Visual Studio Code and paste it into Writer colors are preserved but all indents are gone. When I paste as "Unformatted text" it preserves the indentation but the highlighting is gone. When I copy/paste Python code from PyCharm it preserves both indents and highlighting. Paragraph style remains "Default style". Any suggestion?

OS Arch Linux KDE Plasma VSC 1.47.0 LO Version: 6.3.6.2 Build ID: 6.3.6-2 CPU threads: 12; OS: Linux 5.7; UI render: GL; VCL: kde5; Locale: en-US en_US.UTF-8); UI-Language: en-US Calc: threaded Standard KDE Plasma clipboard manager

code from VS Code

VS Code unformatted

code from PyCharm

C:\fakepath\Pasted_from_VSC.odt

C:\fakepath\Pasted_from_VSC_Unformatted.odt

C:\fakepath\Pasted_from_PyCharm.odt

edit retag close merge delete

Unformatted text: every formatting information is removed before pasting; you only paste a sequence of bare characters. If indentation is preserved, it means it is done either with spaces or tab characters (is your code Python?). Colours are formatting data, therefore they are eliminated.

What you paste "as usual", what do you paste exactly? I mean how is formatted coded so that Writer seems to recognise it. What is the paragraph style of the result?

For a better and complete analysis, edit your question to attach a sample file. Don't use an answer which is reserved for solutions.

( 2020-07-16 14:22:20 +0200 )edit

Your screenshots are useless because 1) you didn't even enable View>Formatted Marks, 2) I can't analyse what's sent to Writer. Attrach (with the paper clip tool), three sample files corresponding to the three screenshots.

Remark: it is usually not good to have too large a font size in code examples because Writer wraps long lines, which could visually change the meaning of the code. This looks like Python and you're lucky that the wrapped line with 2==0): is "protected by(), otherwise your citation would be faulty code-wise (Writer doesn't care for that). You'd be advised to lower the font size to 12pt or even 10pt. Otherwise, format your line to be syntactically correct according to the example language.

In the unformatted case, have you selected the text or already applied some banground highlighting?

( 2020-07-16 16:03:49 +0200 )edit

Thank you for your help. Please bear with me, it's the first time I'm asking for help here. I've just sent three files as attachments. In the unformatted case I didn't select the text. I've noticed that sometimes it is pasted without any background color and sometimes it adds some color, like the black in this case, or sometimes blue. It is somewhat unpredictable but this bothers me less than the main issue of stripping all indentation. I use dark theme in VS Code.

( 2020-07-16 16:14:36 +0200 )edit

I've just sent three files as attachments

How? I don't see them.

To attach sample file, reopen your question with edit. Scroll to the end. Type double Return and use the paperclip tool. Repeat for the other files. The double Return` will neatly separate the download links.

( 2020-07-16 16:29:15 +0200 )edit

Just tried with VS Code on Windows 10 with a development version of LO: https://imgur.com/nxs2PNd. It kept all the indentation correctly...

So many unknowns here: OS? Clipboard manager? Version of VS Code? Version of LO?...

And ultimately, we would need the actual bytes from the clipboard - I have no idea how to get those on systems other than Windows (where I'd use InsideClipboard).

FTR: tried also with LO 6.1, both with spaces and tabs used for indentation. It works here - so either OS, clipboard manager, or VS Code issue. Unlikely to be related to LO version.

My VS Code is 1.47.1.

( 2020-07-16 17:24:33 +0200 )edit

I have updated the question with all information mentioned. I believe this is not only me because there is a (now closed) thread on Reddit exactly about this issue link text

( 2020-07-16 17:37:57 +0200 )edit

I works perfectly when I try to paste in other apps like Thunderbird or GoogleDocs. However, when I paste into MS 365 Office (OneDrive) the result is the same as with LO Writer - indentation is gone.

BTW, while we are on this, why Writer has background highlighting only in the part with text while GoogleDocs keeps background highlighting for the whole block? https://imgur.com/a/ICvTu8J

( 2020-07-16 18:26:40 +0200 )edit

In Writer, there are two "decorations": highlighting and background.

Highlighting will paint only the rectangle occupied by the glyph (the character) as defined by the font metrics. It will not paint any spacing added by the formatting (or styling) such as space above or below the paragraph and the line spacing between lines (which is under user control).

When you define a paragraph background, the rectangle taken in consideration is the largest rectangle containing paragraph text and the user-added spacings above and below this text. Consequently, the full width of lines and line spacing is also covered (painted) with background colour.

Both "decorations" are controlled independently.

( 2020-07-16 18:37:49 +0200 )edit