Skip to content

Commit 472af59

Browse files
authored
more copy SVG fixes (microsoft#203937)
* re-add check for image for context menu, add selector for jupyter rendered SVGs * consisent command name
1 parent 5e6ec06 commit 472af59

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

extensions/ipynb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"webview/context": [
114114
{
115115
"command": "notebook.cellOutput.copy",
116-
"when": "webviewId == 'notebook.output'"
116+
"when": "webviewId == 'notebook.output' && webviewSection == 'image'"
117117
}
118118
]
119119
}

src/vs/workbench/contrib/notebook/browser/controller/cellOutputActions.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ registerAction2(class CopyCellOutputAction extends Action2 {
2323
constructor() {
2424
super({
2525
id: COPY_OUTPUT_COMMAND_ID,
26-
title: localize('notebookActions.copyOutput', "Copy Output"),
26+
title: localize('notebookActions.copyOutput', "Copy Cell Output"),
2727
menu: {
2828
id: MenuId.NotebookOutputToolbar,
2929
when: NOTEBOOK_CELL_HAS_OUTPUTS
@@ -42,7 +42,14 @@ registerAction2(class CopyCellOutputAction extends Action2 {
4242
}
4343

4444
let outputViewModel: ICellOutputViewModel | undefined;
45-
if (!outputContext) {
45+
if (outputContext && 'outputId' in outputContext && typeof outputContext.outputId === 'string') {
46+
outputViewModel = getOutputViewModelFromId(outputContext.outputId, notebookEditor);
47+
} else if (outputContext && 'outputViewModel' in outputContext) {
48+
outputViewModel = outputContext.outputViewModel;
49+
}
50+
51+
if (!outputViewModel) {
52+
// not able to find the output from the provided context, use the active cell
4653
const activeCell = notebookEditor.getActiveCell();
4754
if (!activeCell) {
4855
return;
@@ -55,10 +62,6 @@ registerAction2(class CopyCellOutputAction extends Action2 {
5562
} else {
5663
outputViewModel = activeCell.outputsViewModels.find(output => output.pickedMimeType?.isTrusted);
5764
}
58-
} else if ('outputId' in outputContext && typeof outputContext.outputId === 'string') {
59-
outputViewModel = getOutputViewModelFromId(outputContext.outputId, notebookEditor);
60-
} else {
61-
outputViewModel = outputContext.outputViewModel;
6265
}
6366

6467
if (!outputViewModel) {

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,9 @@ async function webviewPreloads(ctx: PreloadContext) {
14001400
let image = outputElement?.querySelector('img');
14011401

14021402
if (!image) {
1403-
const svgImage = outputElement?.querySelector('svg.output-image');
1403+
const svgImage = outputElement?.querySelector('svg.output-image') ??
1404+
outputElement?.querySelector('div.svgContainerStyle > svg');
1405+
14041406
if (svgImage) {
14051407
image = new Image();
14061408
image.src = 'data:image/svg+xml,' + encodeURIComponent(svgImage.outerHTML);

0 commit comments

Comments
 (0)