Enable pasting of image attachments by default for ipynb (#166058)

Fixes https://github.com/microsoft/vscode-jupyter/issues/11987
This commit is contained in:
Matt Bierner 2022-11-10 16:46:31 -08:00 committed by GitHub
parent 8294940ac6
commit 1ccc8d438b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 12 deletions

View file

@ -32,14 +32,11 @@
"configuration": [
{
"properties": {
"ipynb.experimental.pasteImages.enabled": {
"ipynb.pasteImagesAsAttachments.enabled": {
"type": "boolean",
"scope": "resource",
"markdownDescription": "%ipynb.experimental.pasteImages.enabled%",
"default": false,
"tags": [
"experimental"
]
"markdownDescription": "%ipynb.pasteImagesAsAttachments.enabled%",
"default": true
}
}
}

View file

@ -1,5 +1,5 @@
{
"displayName": ".ipynb Support",
"description": "Provides basic support for opening and reading Jupyter's .ipynb notebook files",
"ipynb.experimental.pasteImages.enabled":"Enable/Disable pasting images into markdown cells within ipynb files. Requires enabling `#editor.experimental.pasteActions.enabled#`."
"ipynb.pasteImagesAsAttachments.enabled": "Enable/disable pasting of images into Markdown cells in ipynb notebook files. Pasted images are inserted as attachments to the cell."
}

View file

@ -85,7 +85,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(notebookImagePasteSetup());
const enabled = vscode.workspace.getConfiguration('ipynb').get('experimental.pasteImages.enabled', false);
const enabled = vscode.workspace.getConfiguration('ipynb').get('pasteImagesAsAttachments.enabled', false);
if (enabled) {
const cleaner = new AttachmentCleaner();
context.subscriptions.push(cleaner);

View file

@ -15,7 +15,7 @@ class CopyPasteEditProvider implements vscode.DocumentPasteEditProvider {
_token: vscode.CancellationToken
): Promise<vscode.DocumentPasteEdit | undefined> {
const enabled = vscode.workspace.getConfiguration('ipynb', document).get('experimental.pasteImages.enabled', false);
const enabled = vscode.workspace.getConfiguration('ipynb', document).get('pasteImagesAsAttachments.enabled', false);
if (!enabled) {
return undefined;
}

View file

@ -10,6 +10,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { createStringDataTransferItem, UriList, VSDataTransfer } from 'vs/base/common/dataTransfer';
import { Disposable } from 'vs/base/common/lifecycle';
import { Mimes } from 'vs/base/common/mime';
import { Schemas } from 'vs/base/common/network';
import { generateUuid } from 'vs/base/common/uuid';
import { toVSDataTransfer } from 'vs/editor/browser/dnd';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
@ -69,9 +70,12 @@ export class CopyPasteController extends Disposable implements IEditorContributi
}
private arePasteActionsEnabled(model: ITextModel): boolean {
return this._configurationService.getValue('editor.experimental.pasteActions.enabled', {
resource: model.uri
});
if (this._configurationService.getValue('editor.experimental.pasteActions.enabled', { resource: model.uri })) {
return true;
}
// TODO: This check is only here to support enabling `ipynb.pasteImagesAsAttachments.enabled` by default
return model.uri.scheme === Schemas.vscodeNotebookCell;
}
private handleCopy(e: ClipboardEvent) {