Update paste/drop preference settings (#233261)
Makes it a simple array of kinds for now. We can add the mime type variation later if needed Also makes the paste with imports have a better hierarchy. This lets you setup a keybinding for `text.updateImports` that will work across all languages that support it
This commit is contained in:
Родитель
1643da069d
Коммит
20e2977a10
|
@ -224,7 +224,7 @@
|
|||
"configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors": "Suppresses semantic errors on web even when project wide IntelliSense is enabled. This is always on when project wide IntelliSense is not enabled or available. See `#typescript.tsserver.web.projectWideIntellisense.enabled#`",
|
||||
"configuration.tsserver.web.typeAcquisition.enabled": "Enable/disable package acquisition on the web. This enables IntelliSense for imported packages. Requires `#typescript.tsserver.web.projectWideIntellisense.enabled#`. Currently not supported for Safari.",
|
||||
"configuration.tsserver.nodePath": "Run TS Server on a custom Node installation. This can be a path to a Node executable, or 'node' if you want VS Code to detect a Node installation.",
|
||||
"configuration.updateImportsOnPaste": "Enable updating imports when pasting code. Requires TypeScript 5.7+.\n\nBy default this shows a option to update imports after pasting. You can use the `#editor.pasteAs.preferences#` setting to update imports automatically when pasting: `\"editor.pasteAs.preferences\": [{ \"kind\": \"text.jsts.pasteWithImports\" }]`.",
|
||||
"configuration.updateImportsOnPaste": "Enable updating imports when pasting code. Requires TypeScript 5.7+.\n\nBy default this shows a option to update imports after pasting. You can use the `#editor.pasteAs.preferences#` setting to update imports automatically when pasting: `\"editor.pasteAs.preferences\": [ \"text.updateImports.jsts\" ]`.",
|
||||
"configuration.expandableHover": "Enable/disable expanding on hover.",
|
||||
"walkthroughs.nodejsWelcome.title": "Get started with JavaScript and Node.js",
|
||||
"walkthroughs.nodejsWelcome.description": "Make the most of Visual Studio Code's first-class JavaScript experience.",
|
||||
|
|
|
@ -42,7 +42,7 @@ const enabledSettingId = 'updateImportsOnPaste.enabled';
|
|||
|
||||
class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {
|
||||
|
||||
static readonly kind = vscode.DocumentDropOrPasteEditKind.Empty.append('text', 'jsts', 'pasteWithImports');
|
||||
static readonly kind = vscode.DocumentDropOrPasteEditKind.Empty.append('text', 'updateImports', 'jsts');
|
||||
static readonly metadataMimeType = 'application/vnd.code.jsts.metadata';
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -109,7 +109,7 @@ registerEditorAction(class extends EditorAction {
|
|||
}
|
||||
});
|
||||
|
||||
export type PreferredPasteConfiguration = ReadonlyArray<{ readonly kind: string; readonly mimeType?: string }>;
|
||||
export type PreferredPasteConfiguration = string;
|
||||
|
||||
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
|
||||
...editorConfigurationBaseNode,
|
||||
|
@ -117,24 +117,11 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
|
|||
[pasteAsPreferenceConfig]: {
|
||||
type: 'array',
|
||||
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
|
||||
description: nls.localize('preferredDescription', "Configures the preferred type of edit to use when pasting content.\n\nThis is an ordered list of edit kinds with optional mime types for the content being pasted. The first available edit of a preferred kind will be used."),
|
||||
description: nls.localize('preferredDescription', "Configures the preferred type of edit to use when pasting content.\n\nThis is an ordered list of edit kinds. The first available edit of a preferred kind will be used."),
|
||||
default: [],
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['kind'],
|
||||
properties: {
|
||||
mimeType: {
|
||||
type: 'string',
|
||||
description: nls.localize('mimeType', "The optional mime type that this preference applies to. If not provided, the preference will be used for all mime types."),
|
||||
},
|
||||
kind: {
|
||||
type: 'string',
|
||||
description: nls.localize('kind', "The kind identifier of the paste edit."),
|
||||
}
|
||||
},
|
||||
defaultSnippets: [
|
||||
{ body: { kind: '$1' } }
|
||||
]
|
||||
type: 'string',
|
||||
description: nls.localize('kind', "The kind identifier of the paste edit."),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -660,13 +660,11 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
}
|
||||
}
|
||||
|
||||
private getInitialActiveEditIndex(model: ITextModel, edits: readonly DocumentPasteEdit[]) {
|
||||
const preferredProviders = this._configService.getValue<PreferredPasteConfiguration>(pasteAsPreferenceConfig, { resource: model.uri });
|
||||
private getInitialActiveEditIndex(model: ITextModel, edits: readonly DocumentPasteEdit[]): number {
|
||||
const preferredProviders = this._configService.getValue<PreferredPasteConfiguration[]>(pasteAsPreferenceConfig, { resource: model.uri });
|
||||
for (const config of Array.isArray(preferredProviders) ? preferredProviders : []) {
|
||||
const desiredKind = new HierarchicalKind(config.kind);
|
||||
const editIndex = edits.findIndex(edit =>
|
||||
desiredKind.contains(edit.kind)
|
||||
&& (!config.mimeType || (edit.handledMimeType && matchesMimeType(config.mimeType, [edit.handledMimeType]))));
|
||||
const desiredKind = new HierarchicalKind(config);
|
||||
const editIndex = edits.findIndex(edit => desiredKind.contains(edit.kind));
|
||||
if (editIndex >= 0) {
|
||||
return editIndex;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ registerEditorCommand(new class extends EditorCommand {
|
|||
}
|
||||
});
|
||||
|
||||
export type PreferredDropConfiguration = ReadonlyArray<{ readonly kind: string; readonly mimeType?: string }>;
|
||||
export type PreferredDropConfiguration = string;
|
||||
|
||||
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
|
||||
...editorConfigurationBaseNode,
|
||||
|
@ -60,24 +60,11 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
|
|||
[dropAsPreferenceConfig]: {
|
||||
type: 'array',
|
||||
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
|
||||
description: nls.localize('preferredDescription', "Configures the preferred type of edit to use when dropping content.\n\nThis is an ordered list of edit kinds with optional mime types for the content being dropped. The first available edit of a preferred kind will be used."),
|
||||
description: nls.localize('preferredDescription', "Configures the preferred type of edit to use when dropping content.\n\nThis is an ordered list of edit kinds. The first available edit of a preferred kind will be used."),
|
||||
default: [],
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['kind'],
|
||||
properties: {
|
||||
mimeType: {
|
||||
type: 'string',
|
||||
description: nls.localize('mimeType', "The optional mime type that this preference applies to. If not provided, the preference will be used for all mime types."),
|
||||
},
|
||||
kind: {
|
||||
type: 'string',
|
||||
description: nls.localize('kind', "The kind identifier of the drop edit."),
|
||||
}
|
||||
},
|
||||
defaultSnippets: [
|
||||
{ body: { kind: '$1' } }
|
||||
]
|
||||
type: 'string',
|
||||
description: nls.localize('kind', "The kind identifier of the drop edit."),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -3,11 +3,19 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IAction } from '../../../../base/common/actions.js';
|
||||
import { coalesce } from '../../../../base/common/arrays.js';
|
||||
import { CancelablePromise, createCancelablePromise, raceCancellation } from '../../../../base/common/async.js';
|
||||
import { VSDataTransfer, matchesMimeType } from '../../../../base/common/dataTransfer.js';
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { VSDataTransfer } from '../../../../base/common/dataTransfer.js';
|
||||
import { isCancellationError } from '../../../../base/common/errors.js';
|
||||
import { HierarchicalKind } from '../../../../base/common/hierarchicalKind.js';
|
||||
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
|
||||
import { localize } from '../../../../nls.js';
|
||||
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
|
||||
import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { LocalSelectionTransfer } from '../../../../platform/dnd/browser/dnd.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { toExternalVSDataTransfer } from '../../../browser/dnd.js';
|
||||
import { ICodeEditor } from '../../../browser/editorBrowser.js';
|
||||
import { EditorOption } from '../../../common/config/editorOptions.js';
|
||||
|
@ -21,17 +29,9 @@ import { DraggedTreeItemsIdentifier } from '../../../common/services/treeViewsDn
|
|||
import { ITreeViewsDnDService } from '../../../common/services/treeViewsDndService.js';
|
||||
import { CodeEditorStateFlag, EditorStateCancellationTokenSource } from '../../editorState/browser/editorState.js';
|
||||
import { InlineProgressManager } from '../../inlineProgress/browser/inlineProgress.js';
|
||||
import { localize } from '../../../../nls.js';
|
||||
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
|
||||
import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { LocalSelectionTransfer } from '../../../../platform/dnd/browser/dnd.js';
|
||||
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
import { PreferredDropConfiguration } from './dropIntoEditorContribution.js';
|
||||
import { sortEditsByYieldTo } from './edit.js';
|
||||
import { PostEditWidgetManager } from './postEditWidget.js';
|
||||
import { isCancellationError } from '../../../../base/common/errors.js';
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { PreferredDropConfiguration } from './dropIntoEditorContribution.js';
|
||||
import { IAction } from '../../../../base/common/actions.js';
|
||||
|
||||
export const dropAsPreferenceConfig = 'editor.dropIntoEditor.preferences';
|
||||
|
||||
|
@ -174,13 +174,11 @@ export class DropIntoEditorController extends Disposable implements IEditorContr
|
|||
};
|
||||
}
|
||||
|
||||
private getInitialActiveEditIndex(model: ITextModel, edits: ReadonlyArray<DocumentDropEdit & { readonly providerId?: string }>) {
|
||||
const preferredProviders = this._configService.getValue<PreferredDropConfiguration>(dropAsPreferenceConfig, { resource: model.uri });
|
||||
private getInitialActiveEditIndex(model: ITextModel, edits: ReadonlyArray<DocumentDropEdit>): number {
|
||||
const preferredProviders = this._configService.getValue<PreferredDropConfiguration[]>(dropAsPreferenceConfig, { resource: model.uri });
|
||||
for (const config of Array.isArray(preferredProviders) ? preferredProviders : []) {
|
||||
const desiredKind = new HierarchicalKind(config.kind);
|
||||
const editIndex = edits.findIndex(edit =>
|
||||
(edit.kind && desiredKind.contains(edit.kind))
|
||||
&& (!config.mimeType || (edit.handledMimeType && matchesMimeType(config.mimeType, [edit.handledMimeType]))));
|
||||
const desiredKind = new HierarchicalKind(config);
|
||||
const editIndex = edits.findIndex(edit => edit.kind && desiredKind.contains(edit.kind));
|
||||
if (editIndex >= 0) {
|
||||
return editIndex;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче