Skip to content

getPasteEdits returns wrong range for primary editย #58936

@mjbvz

Description

@mjbvz

๐Ÿ”Ž Search Terms

  • getPasteEdits
  • Paste with imports

๐Ÿ•— Version & Regression Information

5.6.0-dev.20240619

โฏ Playground Link

No response

๐Ÿ’ป Code

a.ts

export interface Foo { }

export const foo: Foo = {}
  1. On line 3, copy Foo
  2. Paste into a file b.ts at the | (notice the blank lines before and after):
|

๐Ÿ™ Actual behavior

The returned edits are at the same location:

    {"seq":0,"type":"response","command":"getPasteEdits","request_seq":166,"success":true,"performanceData":{"updateGraphDurationMs":1.7999577522277832},"body":{"edits":[{"fileName":"/Users/matb/projects/sandbox/b.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { Foo } from \"./a\";\n"},{"start":{"line":1,"offset":2},"end":{"line":1,"offset":2},"newText":"Foo"}]}],"fixId":"providePostPasteEdits"}}
Info 567  [13:03:44.720] request:
    {
      "seq": 167,
      "type": "request",
      "command": "updateOpen",
      "arguments": {
        "changedFiles": [
          {
            "fileName": "/Users/matb/projects/sandbox/b.ts",
            "textChanges": [
              {
                "newText": "import { Foo } from \"./a\";\n",
                "start": {
                  "line": 1,
                  "offset": 1
                },
                "end": {
                  "line": 1,
                  "offset": 1
                }
              },
              {
                "newText": "Foo",
                "start": {
                  "line": 1,
                  "offset": 1
                },
                "end": {
                  "line": 1,
                  "offset": 1
                }
              }
            ]
          }
        ],
        "closedFiles": [],
        "openFiles": []
      }
    }

This causes VS Code to place the cursor incorrectly after applying the edit

๐Ÿ™‚ Expected behavior

There should be two edits: the import one on line 1 and the normal paste on line 2

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions