Skip to content

Commit

Permalink
Enable pasting of image attachments by default for ipynb (#166058)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Nov 11, 2022
1 parent 8294940 commit 1ccc8d4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
9 changes: 3 additions & 6 deletions extensions/ipynb/package.json
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/ipynb/package.nls.json
@@ -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."
}
2 changes: 1 addition & 1 deletion extensions/ipynb/src/ipynbMain.ts
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion extensions/ipynb/src/notebookImagePaste.ts
Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions src/vs/editor/contrib/copyPaste/browser/copyPasteController.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1ccc8d4

Please sign in to comment.