Skip to content

Commit

Permalink
notebooks: fix default selection of untrusted renderer
Browse files Browse the repository at this point in the history
Fixes #118584
  • Loading branch information
connor4312 committed Jun 3, 2021
1 parent 788e39a commit a56ef18
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Disposable } from 'vs/base/common/lifecycle';
import { ICellOutputViewModel, IGenericCellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { ICellOutput, IOrderedMimeType, mimeTypeIsMergeable } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellOutput, IOrderedMimeType, mimeTypeIsMergeable, RENDERER_NOT_AVAILABLE } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';

let handle = 0;
Expand Down Expand Up @@ -49,12 +49,17 @@ export class CellOutputViewModel extends Disposable implements ICellOutputViewMo

resolveMimeTypes(textModel: NotebookTextModel, kernelProvides: readonly string[] | undefined): [readonly IOrderedMimeType[], number] {
const mimeTypes = this._notebookService.getMimeTypeInfo(textModel, kernelProvides, this.model);
let index = -1;
if (this._pickedMimeType) {
index = mimeTypes.findIndex(mimeType => mimeType.rendererId === this._pickedMimeType!.rendererId && mimeType.mimeType === this._pickedMimeType!.mimeType && mimeType.isTrusted);
}

// there is at least one mimetype which is safe and can be rendered by the core
if (!this._pickedMimeType) {
return [mimeTypes, 0];
if (index === -1) {
index = mimeTypes.findIndex(mimeType => mimeType.rendererId !== RENDERER_NOT_AVAILABLE && mimeType.isTrusted);
}

return [mimeTypes, Math.max(mimeTypes.findIndex(mimeType => mimeType.rendererId === this._pickedMimeType!.rendererId && mimeType.mimeType === this._pickedMimeType!.mimeType && mimeType.isTrusted), 0)];
return [mimeTypes, Math.max(index, 0)];
}

toRawJSON() {
Expand Down

0 comments on commit a56ef18

Please sign in to comment.