Skip to content

Commit

Permalink
fixes #40674
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 22, 2017
1 parent e1814cd commit 51b3699
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/vs/base/browser/htmlContentRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface RenderOptions {
inline?: boolean;
actionCallback?: (content: string, event?: IMouseEvent) => void;
codeBlockRenderer?: (modeId: string, value: string) => string | Thenable<string>;
codeBlockRenderCallback?: () => void;
}

function createElement(options: RenderOptions): HTMLElement {
Expand Down Expand Up @@ -126,7 +127,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
Promise.all([value, withInnerHTML]).then(values => {
const promise = Promise.all([value, withInnerHTML]).then(values => {
const strValue = values[0] as string;
const span = element.querySelector(`div[data-code="${id}"]`);
if (span) {
Expand All @@ -135,6 +136,11 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
}).catch(err => {
// ignore
});

if (options.codeBlockRenderCallback) {
promise.then(options.codeBlockRenderCallback);
}

return `<div class="code" data-code="${id}">${escape(code)}</div>`;
}

Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/hover/hoverWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent
this.updateFont();

this._editor.layoutContentWidget(this);
this.onContentsChange();
}

protected onContentsChange(): void {
this.scrollbar.scanDomNode();
}

Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/contrib/hover/modesContentHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,17 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
private _colorPicker: ColorPickerWidget;

private renderDisposable: IDisposable = EmptyDisposable;
private toDispose: IDisposable[];
private toDispose: IDisposable[] = [];

constructor(editor: ICodeEditor, markdownRenderner: MarkdownRenderer) {
super(ModesContentHoverWidget.ID, editor);

this._computer = new ModesContentComputer(this._editor);
this._highlightDecorations = [];
this._isChangingDecorations = false;

this._markdownRenderer = markdownRenderner;
markdownRenderner.onDidRenderCodeBlock(this.onContentsChange, this, this.toDispose);

this._hoverOperation = new HoverOperation(
this._computer,
Expand All @@ -184,7 +186,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
result => this._withResult(result, false)
);

this.toDispose = [];
this.toDispose.push(dom.addStandardDisposableListener(this.getDomNode(), dom.EventType.FOCUS, () => {
if (this._colorPicker) {
dom.addClass(this.getDomNode(), 'colorpicker-hover');
Expand Down
7 changes: 6 additions & 1 deletion src/vs/editor/contrib/markdown/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { tokenizeToString } from 'vs/editor/common/modes/textToHtmlTokenizer';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import Event, { Emitter } from 'vs/base/common/event';

export class MarkdownRenderer {

private _onDidRenderCodeBlock = new Emitter<void>();
readonly onDidRenderCodeBlock: Event<void> = this._onDidRenderCodeBlock.event;

private readonly _options: RenderOptions;

constructor(
Expand All @@ -42,7 +46,8 @@ export class MarkdownRenderer {
}).then(code => {
return `<span style="font-family: ${editor.getConfiguration().fontInfo.fontFamily}">${code}</span>`;
});
}
},
codeBlockRenderCallback: () => this._onDidRenderCodeBlock.fire()
};
}

Expand Down

0 comments on commit 51b3699

Please sign in to comment.