Skip to content

Paste into editor with format on paste removes pasted word #48006

Closed

Description

TS Template added by Matt Bierner (@mjbvz)

TypeScript Version: @4.7.0-dev.20220222

Search Terms

  • Format on paste
  • format

I have auto save enabled and format on paste. When I paste a string into a another string, that string is removed. See

Recording 2022-02-08 at 12 51 17

//cc Sandeep Somavarapu (@sandy081)

Activity

  1. hediet commented on Feb 21, 2022

    @hediet
    Member

    I cannot reproduce this on windows. Up for a quick meeting?

  2. bpasero commented on Feb 21, 2022

    @bpasero
    Author

    Yes

  3. bpasero commented on Feb 21, 2022

    @bpasero
    Author

    Henning figured out that this is a bug in the typescript formatter and it reproduces as simple as with this:

    const x = f('aaaa', 'aaaa').x()

    When you try to paste the aaaa into the second location.

  4. removed their assignment
    on Feb 23, 2022
  5. mjbvz commented on Feb 23, 2022

    @mjbvz
    Contributor

    Here's the format request I see pasting into the first argument in the above example:

    [Trace  - 00:27:06.888] <syntax> Sending request: format (5). Response expected: yes. Current queue length: 0
    Arguments: {
        "file": "/Users/matb/projects/san/index.ts",
        "line": 1,
        "offset": 14,
        "endLine": 1,
        "endOffset": 18
    }
    [Trace  - 00:27:06.919] <syntax> Response received: format (5). Request took 32 ms. Success: true 
    Result: [
        {
            "start": {
                "line": 1,
                "offset": 13
            },
            "end": {
                "line": 1,
                "offset": 23
            },
            "newText": ""
        }
    ]
    
  6. 6 remaining items

  7. sandersn commented on Apr 29, 2022

    @sandersn
    Member

    So far, it looks like the tree walking part of the formatter doesn't correctly increment the scanner, so the end-of-tree section of the code ends up formatting ( ) instead of ( "bar".

    Now I have to go understand how the tree walk works.

  8. sandersn commented on Apr 29, 2022

    @sandersn
    Member

    Broken in #46875, which is not surprising since that PR adds the end-of-tree section.

    Edit: The tree walk was probably already incorrect, it's just the new end-of-tree code relies on it being correct.

  9. added a commit that references this issue on May 2, 2022
    fcdf1fa
  10. added a commit that references this issue on May 2, 2022
    e73d755
  11. DarinDev1000 commented on Jul 11, 2022

    @DarinDev1000

    I also have this issue on mac

  12. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: FormatterThe issue relates to the built-in formatterFix AvailableA PR has been opened for this issueVS Code PriorityCritical issues that VS Code needs fixed in the current TypeScript milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions