Skip to content

Commit f5ccc12

Browse files
committed
cell renderer tweak wrt to tt policy
1 parent feca527 commit f5ccc12

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/vs/base/browser/dom.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ export function clearNode(node: HTMLElement): void {
2222
}
2323
}
2424

25-
export function trustedInnerHTML(node: Element, value: TrustedHTML): void {
26-
// this is a workaround for innerHTML not allowing for "asymetric" accessors
27-
// see https://github.com/microsoft/vscode/issues/106396#issuecomment-692625393
28-
// and https://github.com/microsoft/TypeScript/issues/30024
29-
node.innerHTML = value as unknown as string;
30-
}
31-
3225
export function isInDOM(node: Node | null): boolean {
3326
while (node) {
3427
if (node === document.body) {

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,11 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
553553

554554
class EditorTextRenderer {
555555

556-
private _ttPolicy = window.trustedTypes!.createPolicy('cellRendererEditorText', {
556+
private _ttPolicy = window.trustedTypes?.createPolicy('cellRendererEditorText', {
557557
createHTML(input) { return input; }
558558
});
559559

560-
getRichText(editor: ICodeEditor, modelRange: Range): TrustedHTML | null {
560+
getRichText(editor: ICodeEditor, modelRange: Range): HTMLElement | null {
561561
const model = editor.getModel();
562562
if (!model) {
563563
return null;
@@ -567,22 +567,24 @@ class EditorTextRenderer {
567567
const fontInfo = editor.getOptions().get(EditorOption.fontInfo);
568568
const fontFamily = fontInfo.fontFamily === EDITOR_FONT_DEFAULTS.fontFamily ? fontInfo.fontFamily : `'${fontInfo.fontFamily}', ${EDITOR_FONT_DEFAULTS.fontFamily}`;
569569

570-
const value = `<div style="`
570+
571+
const style = ``
571572
+ `color: ${colorMap[modes.ColorId.DefaultForeground]};`
572573
+ `background-color: ${colorMap[modes.ColorId.DefaultBackground]};`
573574
+ `font-family: ${fontFamily};`
574575
+ `font-weight: ${fontInfo.fontWeight};`
575576
+ `font-size: ${fontInfo.fontSize}px;`
576577
+ `line-height: ${fontInfo.lineHeight}px;`
577-
+ `white-space: pre;`
578-
+ `">`
579-
+ this.getRichTextLines(model, modelRange, colorMap)
580-
+ '</div>';
578+
+ `white-space: pre;`;
579+
580+
const element = DOM.$('div', { style });
581581

582-
return this._ttPolicy.createHTML(value);
582+
const linesHtml = this.getRichTextLinesAsHtml(model, modelRange, colorMap);
583+
element.innerHTML = linesHtml as unknown as string;
584+
return element;
583585
}
584586

585-
private getRichTextLines(model: ITextModel, modelRange: Range, colorMap: string[]): string {
587+
private getRichTextLinesAsHtml(model: ITextModel, modelRange: Range, colorMap: string[]): string | TrustedHTML {
586588
const startLineNumber = modelRange.startLineNumber;
587589
const startColumn = modelRange.startColumn;
588590
const endLineNumber = modelRange.endLineNumber;
@@ -605,7 +607,9 @@ class EditorTextRenderer {
605607
}
606608
}
607609

608-
return result;
610+
return this._ttPolicy
611+
? this._ttPolicy.createHTML(result)
612+
: result;
609613
}
610614

611615
private getDefaultColorMap(): string[] {
@@ -637,7 +641,7 @@ class CodeCellDragImageRenderer {
637641
dragImageContainer.classList.forEach(c => dragImageContainer.classList.remove(c));
638642
dragImageContainer.classList.add('cell-drag-image', 'monaco-list-row', 'focused', `${type}-cell-row`);
639643

640-
const editorContainer = dragImageContainer.querySelector('.cell-editor-container');
644+
const editorContainer: HTMLElement | null = dragImageContainer.querySelector('.cell-editor-container');
641645
if (!editorContainer) {
642646
return null;
643647
}
@@ -646,8 +650,7 @@ class CodeCellDragImageRenderer {
646650
if (!richEditorText) {
647651
return null;
648652
}
649-
650-
DOM.trustedInnerHTML(editorContainer, richEditorText);
653+
DOM.reset(editorContainer, richEditorText);
651654

652655
return dragImageContainer;
653656
}

0 commit comments

Comments
 (0)