mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Show warning when pasteAs fails (#202300)
For #188736 Show an inline message when a requested pasteAs keybinding fails
This commit is contained in:
parent
3822928d40
commit
6e9b9a4543
|
@ -33,6 +33,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
|||
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
|
||||
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { PostEditWidgetManager } from './postEditWidget';
|
||||
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
|
||||
|
||||
export const changePasteTypeCommandId = 'editor.changePasteType';
|
||||
|
||||
|
@ -212,6 +213,7 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
return;
|
||||
}
|
||||
|
||||
MessageController.get(this._editor)?.closeMessage();
|
||||
this._currentPasteOperation?.cancel();
|
||||
this._currentPasteOperation = undefined;
|
||||
|
||||
|
@ -221,7 +223,10 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this.isPasteAsEnabled()) {
|
||||
if (
|
||||
!this.isPasteAsEnabled()
|
||||
&& !this._pasteAsActionContext // Still enable if paste as was explicitly requested
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -240,8 +245,19 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
|
||||
const allProviders = this._languageFeaturesService.documentPasteEditProvider
|
||||
.ordered(model)
|
||||
.filter(provider => provider.pasteMimeTypes?.some(type => matchesMimeType(type, allPotentialMimeTypes)));
|
||||
.filter(provider => {
|
||||
if (this._pasteAsActionContext?.preferredId) {
|
||||
if (this._pasteAsActionContext.preferredId !== provider.id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return provider.pasteMimeTypes?.some(type => matchesMimeType(type, allPotentialMimeTypes));
|
||||
});
|
||||
if (!allProviders.length) {
|
||||
if (this._pasteAsActionContext?.preferredId) {
|
||||
this.showPasteAsNoEditMessage(selections, this._pasteAsActionContext?.preferredId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -258,6 +274,10 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
}
|
||||
}
|
||||
|
||||
private showPasteAsNoEditMessage(selections: readonly Selection[], editId: string) {
|
||||
MessageController.get(this._editor)?.showMessage(localize('pasteAsError', "No paste edits for '{0}' found", editId), selections[0].getStartPosition());
|
||||
}
|
||||
|
||||
private doPasteInline(allProviders: readonly DocumentPasteEditProvider[], selections: readonly Selection[], dataTransfer: VSDataTransfer, metadata: CopyMetadata | undefined, context: DocumentPasteContext): void {
|
||||
const p = createCancelablePromise(async (token) => {
|
||||
const editor = this._editor;
|
||||
|
@ -339,6 +359,9 @@ export class CopyPasteController extends Disposable implements IEditorContributi
|
|||
}
|
||||
|
||||
if (!providerEdits.length) {
|
||||
if (context.only) {
|
||||
this.showPasteAsNoEditMessage(selections, context.only);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue