Issue with preserving code formatting when copying from Visual Studio Code to Google Docs [closed]
Asked Answered
L

2

6

I used to copy code from Visual Studio Code (VSC) and paste it into Google Docs on Google Drive without any issues, preserving the indentation and styles. However, in the past three months, all the indentation gets lost when pasting into Google Docs. I have to manually reformat everything, which is time-consuming and hampers my note-taking process.

What could have changed, and how can I fix this issue? I want to restore the previous behavior where the indentation and styles are preserved when copying code from VSC to Google Docs.

enter image description here

> Version: 1.80.1 (Universal) Commit: 74f6148eb9ea00507ec113ec51c489d6ffb4b771 Date:
> 2023-07-12T17:20:23.298Z Electron: 22.3.14 ElectronBuildId: 21893604
> Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0
> OS: Darwin arm64 22.5.0

Examples:

  1. Before enter image description here

  2. Now enter image description here

But when copying and past in translate.google it does not lose indentation, but when copying from translate.google to Google Docs it loses only the black background and colors of code but saves indentation. Maybe the problem happens in Google Docs, not in VSC.

enter image description here

Thank you!

Lipsey answered 16/7, 2023 at 10:58 Comment(5)
is indentation lost when pasting into any other text input in any other application?Ribonuclease
@Ribonuclease I disabled all extensions in VSC and this does not help. But when copying and past in translate.google it does not lose indentation, but when copying from translate.google to Google Docs it loses only the black background and colors of code but saves indentation. Maybe the problem happens in Google Docs, not in VSC.Lipsey
any difference if you use the Copy With Syntax Highlighting command in VS Code's command palette?Ribonuclease
If I cut and paste into an intermediate editor (LInux's Kate in my case) the indentation isn't lost. If I then copy from Kate into Google docs it is still there! Strange.Schneider
I can't post a solution now because this question is closed. My solution was to switch from Safari to Chrome, on macOS.Cioffred
R
1

Apparently this has been fixed. I made a weak attempt at searching for a corresponding issue ticket but gave up. https://issuetracker.google.com/issues?q=status:closed%20docs%20paste.


Since you mentioned you're on Linux, I have a feeling you might be running into this: Copy-Paste Formatted Code Doesn't Work Properly On Linux (Works On Windows) #122050. Some users also have a similar problem on macOS (source). One user said that paste loses indentation pasting into any other application except for Google Docs (source1, source2), which is perplexing. This person who raised the issue used a program (CopyQ) to inspect their clipboard contents and compared it between Linux and Windows and found that it was slightly different: linux used spaces for indentation, but on Windows, it was  , which is the HTML entity for non-breaking spaces. I suggest that you try inspecting your clipboard contents to see whether it uses spaces or non-breaking spaces and report what you see in that issue ticket's comments along with the textual output (not a screenshot) of running Help: About... command in VS Code's command palette.

In another similar issue ticket: VS Code does not copy first indentation's space #110314, the ticket raiser found that using multi-cursor selection to copy did not have that problem. You could give that a try. See also https://code.visualstudio.com/docs/editor/codebasics#_column-box-selection.

For your reference / learning purposes, I found that issue ticket by googling "github vscode issues indentation copy paste google docs".

Ribonuclease answered 28/9, 2023 at 18:32 Comment(2)
Thanks for exploring. I hope this will be fixed in the Future. It is a big issue in my studying, it is blocking me ((Lipsey
This was fixed maybe from the Google team. I am very happy. Thanks to allLipsey
H
1

It is totally the fault of Docs. When pasting VSCode into a fresh GMail, it is perfect. The same content in a Doc will only destroy the indents. When copying the pasted content from GMail and paste that into Docs, only the text color is preserved. No Indentation and no background color.

Hecker answered 11/10, 2023 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.