How can I keep spaces in pasted source code text with syntax highlighting?

I have a odt text file with some source code copied from Visual Studio Code.
While the copy preserves syntax highlight indentation is removed from the pasted code,even with orthographic corrector and automatic correction disabled.
I’v even tried disabling orphan control from the style.
Spaces are kept if I paste as not formatted text, but I want to keep the colors.

Here is an example of the results I’ve gotten

Hello @paki23, Click edit below your question and use the paper clip to upload the sample file. Thanks.

What is needed is to have a look at what is effectively in the clipboard. Your “Visual Studio Code” puts two copies there:

  • one as unformatted text which is an exact clone (spaces preserved) of your code file

  • the other one as a decorated text

    How is this text decorated? It looks like direct formatting is added to it. In which format does VSC transmit this decoration to LO? If it is a piece of XML, XML rules apply where sequences of space characters (Space, Tab and others) are merged into a single space (line breaks count for a space).

Without knowing precisely what is passed to Writer, it is impossible to answer.

I assume you’re under Windows.

It might be worthwhile to look in extensions website and search for code. Maybe one of the extensions could help with colour. Cheers, Al

No,I’m on Linux,KDE as desktop manager.
What would be the comand to give you the informations you need?

Not a clear idea about it. Probably look in Visual Studio Code to see if copy operation can be customised. I find strange that syntax colouring is also copied. I use KDevelop and it doesn’t copy its decorations which I consider safer and more reliable.

A better option would be to paste unformatted and use one of the extensions suggested by @EarnestAl.

@paki23, Visual Studio Code allows to export as PDF. Most probably copying from the PDF will not work for editing, but give it a try.

@paki23: what have you changed in your question? When editing, make clear what you update.

shooting in the dark

If you have automated block indentation (like from Beautify or the Prettier plugin), it just might be that the indents are not part of your code, but only in the beautifier’s presentation of code. If such is the case (which I cannot determine as i do not have the IDE available at my current computer), the copy operation may retrieve your code as entered only, not capturing the indents as presented.

There may be a setting to alter behavior for “copy as displayed” or “copy as entered”. Again, I cannot determine which is the case.

To be clear the indentation are plain whitespaces characters,not tabstops or other characters.