Skip to content

Commit 05ae151

Browse files
author
Michael Lively
committed
return object, change placeholder
1 parent 16f842e commit 05ae151

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

extensions/ipynb/src/notebookImagePaste.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ class CopyPasteEditProvider implements vscode.DocumentPasteEditProvider {
5151
// create updated metadata for cell (prep for WorkspaceEdit)
5252
const b64string = encodeBase64(fileDataAsUint8);
5353
const startingAttachments = currentCell.metadata.custom?.attachments;
54-
const [newMetadata, revisedFilename] = buildMetadata(b64string, currentCell, filename, filetype, startingAttachments);
54+
const newAttachment = buildAttachment(b64string, currentCell, filename, filetype, startingAttachments);
5555

5656
// build edits
57-
const nbEdit = vscode.NotebookEdit.updateCellMetadata(currentCell.index, newMetadata);
57+
const nbEdit = vscode.NotebookEdit.updateCellMetadata(currentCell.index, newAttachment.metadata);
5858
const workspaceEdit = new vscode.WorkspaceEdit();
5959
workspaceEdit.set(notebookUri, [nbEdit]);
6060

6161
// create a snippet for paste
6262
const pasteSnippet = new vscode.SnippetString();
6363
pasteSnippet.appendText('![');
64-
pasteSnippet.appendPlaceholder(`${revisedFilename}`);
65-
pasteSnippet.appendText(`](attachment:${revisedFilename})`);
64+
pasteSnippet.appendPlaceholder(`${clipboardFilename}`);
65+
pasteSnippet.appendText(`](attachment:${newAttachment.filename})`);
6666

6767
return { insertText: pasteSnippet, additionalEdit: workspaceEdit };
6868
}
@@ -122,7 +122,7 @@ function encodeBase64(buffer: Uint8Array, padded = true, urlSafe = false) {
122122
return output;
123123
}
124124

125-
function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string, filetype: string, startingAttachments: any): [{ [key: string]: any }, string] {
125+
function buildAttachment(b64: string, cell: vscode.NotebookCell, filename: string, filetype: string, startingAttachments: any): { metadata: { [key: string]: any }; filename: string } {
126126
const outputMetadata = { ...cell.metadata };
127127
let tempFilename = filename + filetype;
128128

@@ -142,7 +142,10 @@ function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string,
142142
}
143143
outputMetadata.custom.attachments[tempFilename] = { 'image/png': b64 };
144144
}
145-
return [outputMetadata, tempFilename];
145+
return {
146+
metadata: outputMetadata,
147+
filename: tempFilename
148+
};
146149
}
147150

148151
export function imagePasteSetup() {

0 commit comments

Comments
 (0)