Finalize drop into editor api (#155102)

Fixes #142990
Fixes #149779
This commit is contained in:
Matt Bierner 2022-07-13 12:54:52 -07:00 committed by GitHub
parent bec36ce756
commit 50056f3e78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 73 deletions

View file

@ -28,7 +28,7 @@
"configuration.markdown.links.openLocation.currentGroup": "Open links in the active editor group.",
"configuration.markdown.links.openLocation.beside": "Open links beside the active editor.",
"configuration.markdown.suggest.paths.enabled.description": "Enable/disable path suggestions for markdown links",
"configuration.markdown.editor.drop.enabled": "Enable/disable dropping into the markdown editor to insert shift. Requires enabling `#workbench.experimental.editor.dropIntoEditor.enabled#`.",
"configuration.markdown.editor.drop.enabled": "Enable/disable dropping into the markdown editor to insert shift. Requires enabling `#workbench.editor.dropIntoEditor.enabled#`.",
"configuration.markdown.editor.pasteLinks.enabled": "Enable/disable pasting files into a Markdown editor inserts Markdown links. Requires enabling `#editor.experimental.pasteActions.enabled#`.",
"configuration.markdown.experimental.validate.enabled.description": "Enable/disable all error reporting in Markdown files.",
"configuration.markdown.experimental.validate.referenceLinks.enabled.description": "Validate reference links in Markdown files, e.g. `[link][ref]`. Requires enabling `#markdown.experimental.validate.enabled#`.",

View file

@ -46,7 +46,7 @@ export class DropIntoEditorController extends Disposable implements IEditorContr
this._languageFeaturesService.documentOnDropEditProvider.register('*', new DefaultOnDropProvider(workspaceContextService));
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('workbench.experimental.editor.dropIntoEditor.enabled')) {
if (e.affectsConfiguration('workbench.editor.dropIntoEditor.enabled')) {
this.updateEditorOptions(editor);
}
}));
@ -56,7 +56,7 @@ export class DropIntoEditorController extends Disposable implements IEditorContr
private updateEditorOptions(editor: ICodeEditor) {
editor.updateOptions({
enableDropIntoEditor: this._configurationService.getValue('workbench.experimental.editor.dropIntoEditor.enabled')
enableDropIntoEditor: this._configurationService.getValue('workbench.editor.dropIntoEditor.enabled')
});
}

View file

@ -577,7 +577,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostLanguages.createLanguageStatusItem(extension, id, selector);
},
registerDocumentDropEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentDropEditProvider): vscode.Disposable {
checkProposedApiEnabled(extension, 'textEditorDrop');
return extHostLanguageFeatures.registerDocumentOnDropEditProvider(extension, selector, provider);
}
};

View file

@ -32,7 +32,7 @@ interface IDropOperation {
}
function isDropIntoEditorEnabledGlobally(configurationService: IConfigurationService) {
return configurationService.getValue<boolean>('workbench.experimental.editor.dropIntoEditor.enabled');
return configurationService.getValue<boolean>('workbench.editor.dropIntoEditor.enabled');
}
function isDragIntoEditorEvent(e: DragEvent): boolean {

View file

@ -466,6 +466,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'default': 'both',
'description': localize('layoutControlType', "Controls whether the layout control in the custom title bar is displayed as a single menu button or with multiple UI toggles."),
},
'workbench.editor.dropIntoEditor.enabled': {
'type': 'boolean',
'default': true,
'markdownDescription': localize('dropIntoEditor', "Controls whether you can drag and drop a file into a text editor by holding down `shift` (instead of opening the file in an editor)."),
},
'workbench.experimental.layoutControl.enabled': {
'type': 'boolean',
'tags': ['experimental'],
@ -486,12 +491,6 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'description': localize('layoutControlType', "Controls whether the layout control in the custom title bar is displayed as a single menu button or with multiple UI toggles."),
'markdownDeprecationMessage': localize({ key: 'layoutControlTypeDeprecation', comment: ['{0} is a placeholder for a setting identifier.'] }, "This setting has been deprecated in favor of {0}", '`#workbench.layoutControl.type#`')
},
'workbench.experimental.editor.dropIntoEditor.enabled': {
'type': 'boolean',
'default': true,
'tags': ['experimental'],
'markdownDescription': localize('dropIntoEditor', "Controls whether you can drag and drop a file into a text editor by holding down `shift` (instead of opening the file in an editor)."),
}
}
});

View file

@ -59,7 +59,6 @@ export const allApiProposals = Object.freeze({
terminalExitReason: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalExitReason.d.ts',
testCoverage: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testCoverage.d.ts',
testObserver: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testObserver.d.ts',
textEditorDrop: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textEditorDrop.d.ts',
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',

View file

@ -5407,6 +5407,46 @@ declare module 'vscode' {
provideLinkedEditingRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>;
}
/**
* An edit operation applied {@link DocumentDropEditProvider on drop}.
*/
export class DocumentDropEdit {
/**
* The text or snippet to insert at the drop location.
*/
insertText: string | SnippetString;
/**
* An optional additional edit to apply on drop.
*/
additionalEdit?: WorkspaceEdit;
/**
* @param insertText The text or snippet to insert at the drop location.
*/
constructor(insertText: string | SnippetString);
}
/**
* Provider which handles dropping of resources into a text editor.
*
* The user can drop into a text editor by holding down `shift` while dragging. Requires `workbench.editor.dropIntoEditor.enabled` to be on.
*/
export interface DocumentDropEditProvider {
/**
* Provide edits which inserts the content being dragged and dropped into the document.
*
* @param document The document in which the drop occurred.
* @param position The position in the document where the drop occurred.
* @param dataTransfer A {@link DataTransfer} object that holds data about what is being dragged and dropped.
* @param token A cancellation token.
*
* @return A {@link DocumentDropEdit} or a thenable that resolves to such. The lack of a result can be
* signaled by returning `undefined` or `null`.
*/
provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentDropEdit>;
}
/**
* A tuple of two characters, like a pair of
* opening and closing brackets.
@ -12785,6 +12825,16 @@ declare module 'vscode' {
*/
export function registerLinkedEditingRangeProvider(selector: DocumentSelector, provider: LinkedEditingRangeProvider): Disposable;
/**
* Registers a new {@link DocumentDropEditProvider}.
*
* @param selector A selector that defines the documents this provider applies to.
* @param provider A drop provider.
*
* @return A {@link Disposable} that unregisters this provider when disposed of.
*/
export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider): Disposable;
/**
* Set a {@link LanguageConfiguration language configuration} for a language.
*

View file

@ -1,61 +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/142990
/**
* Provider which handles dropping of resources into a text editor.
*
* The user can drop into a text editor by holding down `shift` while dragging. Requires `workbench.experimental.editor.dropIntoEditor.enabled` to be on.
*/
export interface DocumentDropEditProvider {
/**
* Provide edits which inserts the content being dragged and dropped into the document.
*
* @param document The document in which the drop occurred.
* @param position The position in the document where the drop occurred.
* @param dataTransfer A {@link DataTransfer} object that holds data about what is being dragged and dropped.
* @param token A cancellation token.
*
* @return A {@link DocumentDropEdit} or a thenable that resolves to such. The lack of a result can be
* signaled by returning `undefined` or `null`.
*/
provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentDropEdit>;
}
/**
* An edit operation applied on drop.
*/
export class DocumentDropEdit {
/**
* The text or snippet to insert at the drop location.
*/
insertText: string | SnippetString;
/**
* An optional additional edit to apply on drop.
*/
additionalEdit?: WorkspaceEdit;
/**
* @param insertText The text or snippet to insert at the drop location.
*/
constructor(insertText: string | SnippetString);
}
export namespace languages {
/**
* Registers a new {@link DocumentDropEditProvider}.
*
* @param selector A selector that defines the documents this provider applies to.
* @param provider A drop provider.
*
* @return A {@link Disposable} that unregisters this provider when disposed of.
*/
export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider): Disposable;
}
}