Skip to content

Commit aee288e

Browse files
author
Michael Lively
authored
Merge pull request microsoft#159085 from microsoft/mlively/pasteRefactor
fix notebook image paste given notebook metadata fix
2 parents b59b9c4 + 6273efd commit aee288e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

extensions/ipynb/src/notebookImagePaste.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ function encodeBase64(buffer: Uint8Array, padded = true, urlSafe = false) {
125125

126126
function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string, filetype: string, startingAttachments: any): { [key: string]: any } {
127127
const outputMetadata = { ...cell.metadata };
128-
const customField = cell.metadata.custom;
129-
if (!customField) {
130-
return { 'custom': { 'attachments': { [filename]: { 'image/png': b64 } } } };
131-
}
132128

133-
const attachmentField = cell.metadata.custom.attachments;
134-
if (!attachmentField) {
135-
outputMetadata['attachments'] = { [filename]: { 'image/png': b64 } };
129+
if (!outputMetadata.custom) {
130+
outputMetadata['custom'] = { 'attachments': { [filename]: { 'image/png': b64 } } };
131+
} else if (!outputMetadata.custom.attachments) {
132+
outputMetadata.custom['attachments'] = { [filename]: { 'image/png': b64 } };
136133
} else {
137134
for (let appendValue = 2; filename in startingAttachments; appendValue++) {
138135
const objEntries = Object.entries(startingAttachments[filename]);
@@ -145,6 +142,7 @@ function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string,
145142
}
146143
outputMetadata.custom.attachments[filename] = { 'image/png': b64 };
147144
}
145+
148146
return outputMetadata;
149147
}
150148

0 commit comments

Comments
 (0)