Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird auto-formatting of code upon paste #245

Closed
klippx opened this issue Oct 19, 2017 · 16 comments
Closed

Weird auto-formatting of code upon paste #245

klippx opened this issue Oct 19, 2017 · 16 comments
Labels
bug locked Please open a new issue and fill out the template instead of commenting.

Comments

@klippx
Copy link

klippx commented Oct 19, 2017

Description

In JS files this extension will sometimes mess up indentation upon pasting. The circumstances under which this seems to happen is when having "editor.formatOnPaste": true enabled (something that Atom Keymap adds to your config automatically).

With prettier extension disabled:

vscode_prettier_ok
This is when having prettier disabled. I start out by marking the text and pressing CMD+C, place the cursor where I want to paste, and CMD+V. Everything pastes as one would expect.

With prettier extension enabled and including trailing comma

vscode_prettier_fail
This is after enabling prettier. Again, I mark the text, copy it, paste it. Split second after pasting prettier has formatted everything in a horrific manner.

With prettier extension enabled an excluding trailing comma

I then found out that if I do not mark the last comma in the selection I want to copy+paste, it works even with prettier enabled.

vscode_prettier_enabled_ok

Snippet:

module.exports = ({ config }) => {
  return [
    {
      key: 'some value',
      fn: async (req, res) => {
        return 'some value'
      },
    },
  ]
}

My config:

{
  "workbench.colorTheme": "Oceanic Next Italic",
  "window.nativeTabs": true,
  "editor": {
    "formatOnSave": true,
    "fontFamily": "Fira Code",
    "fontSize": "16",
    "fontLigatures": true,
    "tabSize": 2,
    "tabCompletion": true,
  },
  "prettier": {
    "singleQuote": true,
    "semi": false,
    "trailingComma": "es5",
    "printWidth": 100
  },
  // added by atom keymap
  "atomKeymap.promptV3Features": true,
  "editor.multiCursorModifier": "ctrlCmd",
  "editor.formatOnPaste": true
  // end atom keymap
}
@CiGit
Copy link
Member

CiGit commented Oct 19, 2017

Yep same thing happens by calling the range formatter (Format selection). FormatOnPaste calls the range formatter.

It messes the output if the trailing-comma is selected/pasted.
It throws if it is not selected/pasted.

@CiGit CiGit added the bug label Oct 19, 2017
@CodingDive
Copy link

CodingDive commented Nov 3, 2017

I experience the same, also added a gif inside another issue because I first thought VS code was causing the behaviour. microsoft/vscode#33522

@CiGit
Copy link
Member

CiGit commented Nov 21, 2017

This should be fixed in prettier 1.8 (version we are now bundling)

@CiGit CiGit closed this as completed Nov 21, 2017
@sygint
Copy link

sygint commented Jun 7, 2018

I'm still experiencing this issue with the latest extension 1.5.0

@gabrielmicko
Copy link

Me too in VSCode!

@gabrielmicko
Copy link

I think "editor.formatOnPaste": false, fixed my issue.

@Gwillison415
Copy link

Gwillison415 commented Oct 22, 2018

"editor.formatOnPaste": false did not fix my issue.. the way it imports and formats is whack, but undo fixes it.

@faiz021
Copy link

faiz021 commented Nov 8, 2018

This worked for me: Go to VS Code Settings -> from the User Settings tab -> Text Editor -> Formatting -> Untick the first option 'Format On Paste'

@zenoven
Copy link

zenoven commented Dec 5, 2018

same issue, very annoying

@eddiejaoude
Copy link

Thanks @faiz021 , that worked for me

@jasonpberry
Copy link

This was driving me insane. Found the config and turned it off and I'm happy again :) Of course, now I find the fix here :)

@Drumstix42
Copy link

Drumstix42 commented Jun 19, 2019

This is still an outstanding issue on 1.9.0.
Disabling "Format On Paste" is not a good solution, but merely a workaround.

@ackvf
Copy link

ackvf commented Jul 4, 2019

My "Format on Paste" is disabled since long time ago, but I still experience this!

@Siregar
Copy link

Siregar commented Jul 31, 2019

Still happening... this is so annoying.
VS Code v1.36.1

@menteshynov
Copy link

menteshynov commented Aug 1, 2019

I am setup "editor.formatOnPaste": true, and this is fix my issue. I am use Prettier + ESLint + Airbnb Style Guide

VS Code v1.36.1

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label Apr 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests