Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning when pasteAs fails #202300

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -212,6 +213,7 @@ export class CopyPasteController extends Disposable implements IEditorContributi
return;
}

MessageController.get(this._editor)?.closeMessage();
this._currentPasteOperation?.cancel();
this._currentPasteOperation = undefined;

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -339,6 +359,9 @@ export class CopyPasteController extends Disposable implements IEditorContributi
}

if (!providerEdits.length) {
if (context.only) {
this.showPasteAsNoEditMessage(selections, context.only);
}
return;
}

Expand Down