Skip to content

Commit 7284c3e

Browse files
authored
Use classes for drop/paste edit types (microsoft#151980)
1 parent 48cf67d commit 7284c3e

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

extensions/markdown-language-features/src/languageFeatures/copyPaste.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export function registerPasteProvider(selector: vscode.DocumentSelector) {
2121
}
2222

2323
const snippet = await tryGetUriListSnippet(document, dataTransfer, token);
24-
if (snippet) {
25-
return { insertText: snippet };
26-
}
27-
return undefined;
24+
return snippet ? new vscode.DocumentPasteEdit(snippet) : undefined;
2825
}
2926
}, {
3027
pasteMimeTypes: ['text/uri-list']

extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export function registerDropIntoEditor(selector: vscode.DocumentSelector) {
3232
}
3333

3434
const snippet = await tryGetUriListSnippet(document, dataTransfer, token);
35-
if (snippet) {
36-
return { insertText: snippet };
37-
}
38-
return undefined;
35+
return snippet ? new vscode.DocumentDropEdit(snippet) : undefined;
3936
}
4037
});
4138
}

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
12981298
ViewColumn: extHostTypes.ViewColumn,
12991299
WorkspaceEdit: extHostTypes.WorkspaceEdit,
13001300
// proposed api types
1301+
DocumentDropEdit: extHostTypes.DocumentDropEdit,
1302+
DocumentPasteEdit: extHostTypes.DocumentPasteEdit,
13011303
InlayHint: extHostTypes.InlayHint,
13021304
InlayHintLabelPart: extHostTypes.InlayHintLabelPart,
13031305
InlayHintKind: extHostTypes.InlayHintKind,

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,27 @@ export class DataTransfer {
24802480
}
24812481
}
24822482

2483+
@es5ClassCompat
2484+
export class DocumentDropEdit {
2485+
insertText: string | SnippetString;
2486+
2487+
additionalEdit?: WorkspaceEdit;
2488+
2489+
constructor(insertText: string | SnippetString) {
2490+
this.insertText = insertText;
2491+
}
2492+
}
2493+
2494+
@es5ClassCompat
2495+
export class DocumentPasteEdit {
2496+
insertText: string | SnippetString;
2497+
2498+
additionalEdit?: WorkspaceEdit;
2499+
2500+
constructor(insertText: string | SnippetString) {
2501+
this.insertText = insertText;
2502+
}
2503+
}
24832504

24842505
@es5ClassCompat
24852506
export class ThemeIcon {

src/vscode-dts/vscode.proposed.documentPaste.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ declare module 'vscode' {
4343
/**
4444
* An operation applied on paste
4545
*/
46-
interface DocumentPasteEdit {
46+
class DocumentPasteEdit {
4747
/**
4848
* The text or snippet to insert at the pasted locations.
4949
*/
@@ -53,6 +53,11 @@ declare module 'vscode' {
5353
* An optional additional edit to apply on paste.
5454
*/
5555
readonly additionalEdit?: WorkspaceEdit;
56+
57+
/**
58+
* @param insertText The text or snippet to insert at the pasted locations.
59+
*/
60+
constructor(insertText: string | SnippetString);
5661
}
5762

5863
interface DocumentPasteProviderMetadata {

src/vscode-dts/vscode.proposed.textEditorDrop.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ declare module 'vscode' {
3030
/**
3131
* An edit operation applied on drop.
3232
*/
33-
export interface DocumentDropEdit {
33+
export class DocumentDropEdit {
3434
/**
3535
* The text or snippet to insert at the drop location.
3636
*/
37-
readonly insertText: string | SnippetString;
37+
insertText: string | SnippetString;
3838

3939
/**
4040
* An optional additional edit to apply on drop.
4141
*/
42-
readonly additionalEdit?: WorkspaceEdit;
42+
additionalEdit?: WorkspaceEdit;
43+
44+
/**
45+
* @param insertText The text or snippet to insert at the drop location.
46+
*/
47+
constructor(insertText: string | SnippetString);
4348
}
4449

4550
export namespace languages {

0 commit comments

Comments
 (0)