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

Pasting code destroys indentation of both the pasted code and nearby lines #33760

Closed
wittlesouth opened this issue Sep 3, 2017 · 6 comments · May be fixed by #182934
Closed

Pasting code destroys indentation of both the pasted code and nearby lines #33760

wittlesouth opened this issue Sep 3, 2017 · 6 comments · May be fixed by #182934
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues javascript JavaScript support issues wont-fix

Comments

@wittlesouth
Copy link

  • VSCode Version: Code 1.15.1 (41abd21, 2017-08-16T17:15:57.756Z)
  • OS Version: Darwin x64 16.7.0
  • Extensions:
Extension Author (truncated) Version
vscode-docker Pet 0.0.16
jsx Twe 0.0.1
vscode-eslint dba 1.2.11
python don 0.7.0
debugger-for-chrome msj 3.2.1

Steps to Reproduce:

  1. Start with code that looks like the following:
describe('This is a test', () => {
  it('handles addTag()', (done) => {
    let tagUserUpdated = tagUser.updateField([User.USER_PREFERENCES, User.PREFERENCES_TAGS_SELECTED], 'Tag 2|Tag 1')
    .afterUpdateSuccess()
    const stateTagUpdateSuccess = setStatusMessage(
      clearUserFetching(User.setCurrentUser(stateTagUser, tagUserUpdated), tagUserUpdated), userComponentText.userUpdated
    )
    let store = createStore(testUserState, stateTagUser, applyMiddleware(thunkMiddleware))
    nock(process.env.TEST_URL).put('/users/' + userTestData[User.USER_ID]).reply(200, {})
    testAsync(store, stateTagUpdateStart, stateTagUpdateSuccess, done)
    tagUser.setSelectedTag(store.dispatch, 'Tag 1')
  })
})

  1. copy the 2nd line, and past it before the last line. The last line will be indented two spaces to match (presumably) the code that was pasted. This is a simple example, there are lots of other broken cases. Cutting and pasting code fragments is now significantly less productive than before. This seems to be a recent regression.

Reproduces without extensions: Yes/No

@vscodebot vscodebot bot added the new release label Sep 3, 2017
@vscodebot vscodebot bot added editor editor-core Editor basic functionality labels Sep 3, 2017
@codingthat
Copy link

codingthat commented Sep 18, 2017

I'm also seeing this on:

  • VSCode Version: Code 1.15.1 (41abd21, 2017-08-16T17:16:27.618Z)
  • OS Version: Linux x64 4.4.0-53-generic

IIRC, before upgrading VSCode to 1.15.1, this type of operation had worked flawlessly.

@alexdima
Copy link
Member

@wittlesouth @codingthat This is indeed something that shipped with 1.15. It can be turned off via "editor.autoIndent": false

@alexdima alexdima assigned rebornix and unassigned alexdima Sep 20, 2017
@codingthat
Copy link

Thank you so much @alexandrudima , that works great. This was really annoying until you provided a workaround. :)

@agos
Copy link

agos commented Oct 13, 2017

For what is worth, I am seeing destructive behaviour on paste even with "editor.autoIndent" set to
false. Also setting editor.formatOnPaste to true worked, though.

@alexdima alexdima added editor-autoindent Editor auto indentation issues and removed editor-core Editor basic functionality labels Oct 23, 2017
@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Nov 16, 2017
@alexdima alexdima removed the editor label Nov 23, 2017
@robertopc
Copy link

robertopc commented Jul 19, 2018

I put editor.formatOnPaste to false and this behavior stop.

@rebornix rebornix added the javascript JavaScript support issues label Oct 12, 2020
@rebornix
Copy link
Member

rebornix commented Nov 3, 2020

This is due to the limited architecture (regex based indentation rules and only support limited code styles), we may want to consider using formatters if they exist for indenation adjustment (if interested, we can discuss in #19847).

For this particular issue, if the indentation rules are leading to more trouble than having no auto indent, you can set editor.autoIndent to advanced to disable the regex based indentation adjustment. As we don't have an easy good-enough fix for it, we close it for now and explore better solutions through issues like (#19847 and #34621).

@rebornix rebornix closed this as completed Nov 3, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2020
russelldavis added a commit to russelldavis/vscode that referenced this issue May 19, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue May 19, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines in the same scenarios didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue May 22, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Jun 9, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Jul 18, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Sep 30, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 2, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 3, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 7, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 12, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues javascript JavaScript support issues wont-fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants