Imagine the following file:
// comment
function f() {}
When I press Ctrl+x on the line containing f
, and paste it again, what VS Code does is it creates a buffer with the following contents:
// comment
and then sends this request for paste edits
{
"file": "d:\\scratch\\copypasta\\src\\file.ts",
"pastedText": [
"function f() {}\r\n"
],
"pasteLocations": [
{
"start": {
"line": 2,
"offset": 1
},
"end": {
"line": 2,
"offset": 1
}
}
],
"copiedFrom": {
"file": "d:\\scratch\\copypasta\\src\\file.ts",
"spans": [
{
"start": {
"line": 3,
"offset": 1
},
"end": {
"line": 3,
"offset": 16
}
}
]
}
}
and receives this response.
{
"edits": [
{
"fileName": "d:/scratch/copypasta/src/file.ts",
"textChanges": [
{
"start": {
"line": 1,
"offset": 15
},
"end": {
"line": 1,
"offset": 15
},
"newText": "function f() {}\r\n"
}
]
}
],
"fixId": "providePostPasteEdits"
}
After the paste, the file no longer contains the original contents, and instead contains invalid text.
// commentfunction f() {}
3条答案
按热度按时间lmyy7pcs1#
这不一定是特定于评论的。我认为一个相关的问题是:
这会产生以下文件:
请注意在
g
之前缺少换行符,以及在g
之后多余的换行符。e0uiprwp2#
请稍等,粘贴编辑是什么?我以前好像没遇到过这个词。
g9icjywg3#
Wait, what are paste edits? I don’t think I’ve encountered that term before.
It's basically a command for editors to request a "smarter" copy/paste that can do things like auto-imports. See #57262 and #50187 .