mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Merge pull request #862 from mjbvz/paste-bump
Update for latest copy paste api
This commit is contained in:
1
document-paste/.gitignore
vendored
1
document-paste/.gitignore
vendored
@ -2,3 +2,4 @@ out
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
vscode.*d.ts
|
||||
109
document-paste/package-lock.json
generated
109
document-paste/package-lock.json
generated
@ -7,17 +7,19 @@
|
||||
"": {
|
||||
"name": "document-paste-sample",
|
||||
"version": "0.0.1",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.7",
|
||||
"@types/vscode": "^1.32.0",
|
||||
"@types/vscode": "^1.77.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
||||
"@typescript-eslint/parser": "^5.42.0",
|
||||
"eslint": "^8.26.0",
|
||||
"typescript": "^5.0.2"
|
||||
"typescript": "^5.0.2",
|
||||
"vscode-dts": "^0.3.3"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.69.0"
|
||||
"vscode": "^1.77.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/eslintrc": {
|
||||
@ -129,9 +131,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/vscode": {
|
||||
"version": "1.66.0",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
"version": "1.78.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.78.0.tgz",
|
||||
"integrity": "sha512-LJZIJpPvKJ0HVQDqfOy6W4sNKUBBwyDu1Bs8chHBZOe9MNuKTJtidgZ2bqjhmmWpUb0TIIqv47BFUcVmAsgaVA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "5.42.0",
|
||||
@ -1077,6 +1080,15 @@
|
||||
"integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/kleur": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
|
||||
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/levn": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
|
||||
@ -1157,6 +1169,15 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"dev": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@ -1300,6 +1321,19 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prompts": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
|
||||
"integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"kleur": "^3.0.3",
|
||||
"sisteransi": "^1.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||
@ -1434,6 +1468,12 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/sisteransi": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
|
||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/slash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
||||
@ -1564,6 +1604,20 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vscode-dts": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz",
|
||||
"integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0",
|
||||
"prompts": "^2.1.0",
|
||||
"rimraf": "^3.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"vscode-dts": "index.js"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
@ -1697,7 +1751,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/vscode": {
|
||||
"version": "1.66.0",
|
||||
"version": "1.78.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.78.0.tgz",
|
||||
"integrity": "sha512-LJZIJpPvKJ0HVQDqfOy6W4sNKUBBwyDu1Bs8chHBZOe9MNuKTJtidgZ2bqjhmmWpUb0TIIqv47BFUcVmAsgaVA==",
|
||||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
@ -2374,6 +2430,12 @@
|
||||
"integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"kleur": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
|
||||
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
|
||||
"dev": true
|
||||
},
|
||||
"levn": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
|
||||
@ -2433,6 +2495,12 @@
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"dev": true
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@ -2537,6 +2605,16 @@
|
||||
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
|
||||
"dev": true
|
||||
},
|
||||
"prompts": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
|
||||
"integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"kleur": "^3.0.3",
|
||||
"sisteransi": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"punycode": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||
@ -2609,6 +2687,12 @@
|
||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||
"dev": true
|
||||
},
|
||||
"sisteransi": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
|
||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
||||
"dev": true
|
||||
},
|
||||
"slash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
||||
@ -2699,6 +2783,17 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"vscode-dts": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/vscode-dts/-/vscode-dts-0.3.3.tgz",
|
||||
"integrity": "sha512-JfOsWL0NvfVw0UF9bcTjlv1Onz3Ted7cgpPWKWMnHGB+72t/tn8WFDeKLZO42l2k9KJq/NGS9rFC5gZbyI4FTg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.0",
|
||||
"prompts": "^2.1.0",
|
||||
"rimraf": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
||||
@ -11,11 +11,10 @@
|
||||
"url": "https://github.com/Microsoft/vscode-extension-samples"
|
||||
},
|
||||
"enabledApiProposals": [
|
||||
"textEditorDrop",
|
||||
"documentPaste"
|
||||
],
|
||||
"engines": {
|
||||
"vscode": "^1.69.0"
|
||||
"vscode": "^1.77.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
@ -29,14 +28,17 @@
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"lint": "eslint \"src/**/*.ts\"",
|
||||
"watch": "tsc -watch -p ./"
|
||||
"watch": "tsc -watch -p ./",
|
||||
"download-api": "vscode-dts main && vscode-dts dev",
|
||||
"postinstall": "npm run download-api"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.7",
|
||||
"@types/vscode": "^1.32.0",
|
||||
"@types/vscode": "^1.77.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
||||
"@typescript-eslint/parser": "^5.42.0",
|
||||
"eslint": "^8.26.0",
|
||||
"typescript": "^5.0.2"
|
||||
"typescript": "^5.0.2",
|
||||
"vscode-dts": "^0.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ class CopyCountPasteEditProvider implements vscode.DocumentPasteEditProvider {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const textDataTransferItem = dataTransfer.get('text') ?? dataTransfer.get('text/plain');
|
||||
const textDataTransferItem = dataTransfer.get('text/plain');
|
||||
if (!textDataTransferItem) {
|
||||
return undefined;
|
||||
}
|
||||
@ -42,7 +42,7 @@ class CopyCountPasteEditProvider implements vscode.DocumentPasteEditProvider {
|
||||
const snippet = new vscode.SnippetString();
|
||||
snippet.appendText(`(copy #${count}) ${text}`);
|
||||
|
||||
return { insertText: snippet };
|
||||
return new vscode.DocumentPasteEdit(snippet, 'copyCount', "Insert with copy count sample");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/30066/
|
||||
|
||||
/**
|
||||
* Provider invoked when the user copies and pastes code.
|
||||
*/
|
||||
interface DocumentPasteEditProvider {
|
||||
|
||||
/**
|
||||
* Optional method invoked after the user copies text in a file.
|
||||
*
|
||||
* During {@link prepareDocumentPaste}, an extension can compute metadata that is attached to
|
||||
* a {@link DataTransfer} and is passed back to the provider in {@link provideDocumentPasteEdits}.
|
||||
*
|
||||
* @param document Document where the copy took place.
|
||||
* @param ranges Ranges being copied in the `document`.
|
||||
* @param dataTransfer The data transfer associated with the copy. You can store additional values on this for later use in {@link provideDocumentPasteEdits}.
|
||||
* @param token A cancellation token.
|
||||
*/
|
||||
prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable<void>;
|
||||
|
||||
/**
|
||||
* Invoked before the user pastes into a document.
|
||||
*
|
||||
* In this method, extensions can return a workspace edit that replaces the standard pasting behavior.
|
||||
*
|
||||
* @param document Document being pasted into
|
||||
* @param ranges Currently selected ranges in the document.
|
||||
* @param dataTransfer The data transfer associated with the paste.
|
||||
* @param token A cancellation token.
|
||||
*
|
||||
* @return Optional workspace edit that applies the paste. Return undefined to use standard pasting.
|
||||
*/
|
||||
provideDocumentPasteEdits(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentPasteEdit>;
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation applied on paste
|
||||
*/
|
||||
interface DocumentPasteEdit {
|
||||
/**
|
||||
* The text or snippet to insert at the pasted locations.
|
||||
*/
|
||||
readonly insertText: string | SnippetString;
|
||||
|
||||
/**
|
||||
* An optional additional edit to apply on paste.
|
||||
*/
|
||||
readonly additionalEdit?: WorkspaceEdit;
|
||||
}
|
||||
|
||||
interface DocumentPasteProviderMetadata {
|
||||
/**
|
||||
* Mime types that `provideDocumentPasteEdits` should be invoked for.
|
||||
*
|
||||
* Use the special `files` mimetype to indicate the provider should be invoked if any files are present in the `DataTransfer`.
|
||||
*/
|
||||
readonly pasteMimeTypes: readonly string[];
|
||||
}
|
||||
|
||||
namespace languages {
|
||||
export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable;
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@ class ReverseTextOnDropProvider implements vscode.DocumentDropEditProvider {
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.DocumentDropEdit | undefined> {
|
||||
// Check the data transfer to see if we have some kind of text data
|
||||
const dataTransferItem = dataTransfer.get('text') ?? dataTransfer.get('text/plain');
|
||||
const dataTransferItem = dataTransfer.get('text/plain');
|
||||
if (!dataTransferItem) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user