Skip to content

Commit 6e9b9a4

Browse files
authored
Show warning when pasteAs fails (#202300)
For #188736 Show an inline message when a requested pasteAs keybinding fails
1 parent 3822928 commit 6e9b9a4

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/vs/editor/contrib/dropOrPasteInto/browser/copyPasteController.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
3333
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
3434
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
3535
import { PostEditWidgetManager } from './postEditWidget';
36+
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
3637

3738
export const changePasteTypeCommandId = 'editor.changePasteType';
3839

@@ -212,6 +213,7 @@ export class CopyPasteController extends Disposable implements IEditorContributi
212213
return;
213214
}
214215

216+
MessageController.get(this._editor)?.closeMessage();
215217
this._currentPasteOperation?.cancel();
216218
this._currentPasteOperation = undefined;
217219

@@ -221,7 +223,10 @@ export class CopyPasteController extends Disposable implements IEditorContributi
221223
return;
222224
}
223225

224-
if (!this.isPasteAsEnabled()) {
226+
if (
227+
!this.isPasteAsEnabled()
228+
&& !this._pasteAsActionContext // Still enable if paste as was explicitly requested
229+
) {
225230
return;
226231
}
227232

@@ -240,8 +245,19 @@ export class CopyPasteController extends Disposable implements IEditorContributi
240245

241246
const allProviders = this._languageFeaturesService.documentPasteEditProvider
242247
.ordered(model)
243-
.filter(provider => provider.pasteMimeTypes?.some(type => matchesMimeType(type, allPotentialMimeTypes)));
248+
.filter(provider => {
249+
if (this._pasteAsActionContext?.preferredId) {
250+
if (this._pasteAsActionContext.preferredId !== provider.id) {
251+
return false;
252+
}
253+
}
254+
255+
return provider.pasteMimeTypes?.some(type => matchesMimeType(type, allPotentialMimeTypes));
256+
});
244257
if (!allProviders.length) {
258+
if (this._pasteAsActionContext?.preferredId) {
259+
this.showPasteAsNoEditMessage(selections, this._pasteAsActionContext?.preferredId);
260+
}
245261
return;
246262
}
247263

@@ -258,6 +274,10 @@ export class CopyPasteController extends Disposable implements IEditorContributi
258274
}
259275
}
260276

277+
private showPasteAsNoEditMessage(selections: readonly Selection[], editId: string) {
278+
MessageController.get(this._editor)?.showMessage(localize('pasteAsError', "No paste edits for '{0}' found", editId), selections[0].getStartPosition());
279+
}
280+
261281
private doPasteInline(allProviders: readonly DocumentPasteEditProvider[], selections: readonly Selection[], dataTransfer: VSDataTransfer, metadata: CopyMetadata | undefined, context: DocumentPasteContext): void {
262282
const p = createCancelablePromise(async (token) => {
263283
const editor = this._editor;
@@ -339,6 +359,9 @@ export class CopyPasteController extends Disposable implements IEditorContributi
339359
}
340360

341361
if (!providerEdits.length) {
362+
if (context.only) {
363+
this.showPasteAsNoEditMessage(selections, context.only);
364+
}
342365
return;
343366
}
344367

0 commit comments

Comments
 (0)