more copy SVG fixes (#203937)

* re-add check for image for context menu, add selector for jupyter rendered SVGs

* consisent command name
This commit is contained in:
Aaron Munger 2024-01-31 15:58:00 -08:00 committed by GitHub
parent 5e6ec068b2
commit 472af59e08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View File

@ -113,7 +113,7 @@
"webview/context": [
{
"command": "notebook.cellOutput.copy",
"when": "webviewId == 'notebook.output'"
"when": "webviewId == 'notebook.output' && webviewSection == 'image'"
}
]
}

View File

@ -23,7 +23,7 @@ registerAction2(class CopyCellOutputAction extends Action2 {
constructor() {
super({
id: COPY_OUTPUT_COMMAND_ID,
title: localize('notebookActions.copyOutput', "Copy Output"),
title: localize('notebookActions.copyOutput', "Copy Cell Output"),
menu: {
id: MenuId.NotebookOutputToolbar,
when: NOTEBOOK_CELL_HAS_OUTPUTS
@ -42,7 +42,14 @@ registerAction2(class CopyCellOutputAction extends Action2 {
}
let outputViewModel: ICellOutputViewModel | undefined;
if (!outputContext) {
if (outputContext && 'outputId' in outputContext && typeof outputContext.outputId === 'string') {
outputViewModel = getOutputViewModelFromId(outputContext.outputId, notebookEditor);
} else if (outputContext && 'outputViewModel' in outputContext) {
outputViewModel = outputContext.outputViewModel;
}
if (!outputViewModel) {
// not able to find the output from the provided context, use the active cell
const activeCell = notebookEditor.getActiveCell();
if (!activeCell) {
return;
@ -55,10 +62,6 @@ registerAction2(class CopyCellOutputAction extends Action2 {
} else {
outputViewModel = activeCell.outputsViewModels.find(output => output.pickedMimeType?.isTrusted);
}
} else if ('outputId' in outputContext && typeof outputContext.outputId === 'string') {
outputViewModel = getOutputViewModelFromId(outputContext.outputId, notebookEditor);
} else {
outputViewModel = outputContext.outputViewModel;
}
if (!outputViewModel) {

View File

@ -1400,7 +1400,9 @@ async function webviewPreloads(ctx: PreloadContext) {
let image = outputElement?.querySelector('img');
if (!image) {
const svgImage = outputElement?.querySelector('svg.output-image');
const svgImage = outputElement?.querySelector('svg.output-image') ??
outputElement?.querySelector('div.svgContainerStyle > svg');
if (svgImage) {
image = new Image();
image.src = 'data:image/svg+xml,' + encodeURIComponent(svgImage.outerHTML);