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

Format selection (and thus format-on-paste) causes destructive edits #50076

Closed
richardbullin opened this issue Jul 27, 2022 · 6 comments · Fixed by #50082
Closed

Format selection (and thus format-on-paste) causes destructive edits #50076

richardbullin opened this issue Jul 27, 2022 · 6 comments · Fixed by #50082
Assignees
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Fix Available A PR has been opened for this issue

Comments

@richardbullin
Copy link

Issue Type: Bug

Create a simple template string in a Javascript or Typescript file as below

const TEST_STRING = `${TEST_VAR_1}, this is some text`; 

Copy any text and paste anywhere after the closing expression bracket "}". All text including the last "}" is deleted.

In my example I've copied the word "TEST_STRING " by double clicking on it. I've tried pasting just before the end back tick

const TEST_STRING = `${TEST_VAR_1; 

If you press undo the expected initial result is shown.

const TEST_STRING = `${TEST_VAR_1}, this is some textTEST_STRING`; 

VS Code version: Code 1.69.2 (3b889b090b5ad5793f524b5d1d39fda662b96a2a, 2022-07-18T16:12:52.460Z)
OS version: Windows_NT x64 10.0.19043
Restricted Mode: No

Extensions: none

@mjbvz mjbvz self-assigned this Jul 27, 2022
@mjbvz mjbvz transferred this issue from microsoft/vscode Jul 27, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Jul 27, 2022

Confirmed with ^4.8.0-dev.20220727. Requires editor.formatOnPaste to be enabled

Here's the sequence of events for pasting abc:

[Trace  - 23:33:55.294] <semantic> Sending request: updateOpen (72). Response expected: yes. Current queue length: 0
Arguments: {
    "changedFiles": [
        {
            "fileName": "/Users/matb/projects/san/index.js",
            "textChanges": [
                {
                    "newText": "abc",
                    "start": {
                        "line": 1,
                        "offset": 35
                    },
                    "end": {
                        "line": 1,
                        "offset": 35
                    }
                }
            ]
        }
    ],
    "closedFiles": [],
    "openFiles": []
}
[Trace  - 23:33:55.294] <semantic> Response received: updateOpen (72). Request took 0 ms. Success: true 
Result: true
[Trace  - 23:33:55.295] <syntax> Response received: updateOpen (28). Request took 1 ms. Success: true 
Result: true
[Trace  - 23:33:55.295] <syntax> Sending request: format (29). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "/Users/matb/projects/san/index.js",
    "line": 1,
    "offset": 35,
    "endLine": 1,
    "endOffset": 38
}
[Trace  - 23:33:55.296] <syntax> Response received: format (29). Request took 2 ms. Success: true 
Result: [
    {
        "start": {
            "line": 1,
            "offset": 34
        },
        "end": {
            "line": 1,
            "offset": 96
        },
        "newText": ""
    }
]

@mjbvz
Copy link
Contributor

mjbvz commented Jul 27, 2022

Seems very similar to #48006

@amcasey
Copy link
Member

amcasey commented Jul 27, 2022

Seems very similar to #48006

+1. @sandersn ?

@DanielRosenwasser
Copy link
Member

Simpler repro is

const x = `${0}abc`;

Select abc and run format selection.

Note that:

  1. This repro must have a template string with a substitution
  2. The template tail literal must have some string contents.
  3. There MUST be a semicolon at the end of the current statement.

@DanielRosenwasser
Copy link
Member

Another similar one

foo(`${0} `)
  1. This repro must have a template string with a substitution.
  2. The template tail literal must have some string contents.
  3. The template must be in a call.

@DanielRosenwasser DanielRosenwasser added the Domain: Formatter The issue relates to the built-in formatter label Jul 27, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.8.1 milestone Jul 27, 2022
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript High Priority labels Jul 27, 2022
@DanielRosenwasser DanielRosenwasser changed the title Pasting inside Javascript or Typescript template literal/string deletes content Format selection (and thus format-on-paste) causes destructive edits Jul 27, 2022
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 28, 2022

First appears on [email protected] which is hard to test because VS Code assumes 4.6.* can run with IPC. That means it's one of https://github.com/microsoft/TypeScript/pulls?q=is%3Apr+merged%3A2021-11-29+is%3Aclosed, and likely #46875.

It's been in the product for over 8 months so I guess I feel weird labeling it "High Priority", but I think we should get it fixed for 4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants