Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix background markdown rendering issues #153871

Merged
merged 1 commit into from Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts
Expand Up @@ -1153,22 +1153,25 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
const endTime = Date.now() + deadline.timeRemaining();

const execute = () => {
this._backgroundMarkdownRenderRunning = false;
if (this._isDisposed) {
return;
}
try {
this._backgroundMarkdownRenderRunning = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this flag so that _backgroundMarkdownRendering doesn't bail on the second time through.

if (this._isDisposed) {
return;
}

if (!this.viewModel) {
return;
}
if (!this.viewModel) {
return;
}

const firstMarkupCell = this.viewModel.viewCells.find(cell => cell.cellKind === CellKind.Markup && !this._webview?.markupPreviewMapping.has(cell.id)) as MarkupCellViewModel | undefined;
if (!firstMarkupCell) {
return;
}
const firstMarkupCell = this.viewModel.viewCells.find(cell => cell.cellKind === CellKind.Markup && !this._webview?.markupPreviewMapping.has(cell.id) && !this.cellIsHidden(cell)) as MarkupCellViewModel | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, don't take the cell if it is hidden.

if (!firstMarkupCell) {
return;
}

this._backgroundMarkdownRenderRunning = true;
this.createMarkupPreview(firstMarkupCell);
this.createMarkupPreview(firstMarkupCell);
} finally {
this._backgroundMarkdownRenderRunning = false;
}

if (Date.now() < endTime) {
setTimeout0(execute);
Expand Down Expand Up @@ -2564,10 +2567,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
return;
}

const modelIndex = this.viewModel.getCellIndex(cell);
const foldedRanges = this.viewModel.getHiddenRanges();
const isVisible = !foldedRanges.some(range => modelIndex >= range.start && modelIndex < range.end);
if (!isVisible) {
if (this.cellIsHidden(cell)) {
return;
}

Expand All @@ -2585,6 +2585,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
});
}

private cellIsHidden(cell: ICellViewModel): boolean {
const modelIndex = this.viewModel!.getCellIndex(cell);
const foldedRanges = this.viewModel!.getHiddenRanges();
return foldedRanges.some(range => modelIndex >= range.start && modelIndex <= range.end);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from < to <=, that seems correct here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what other issue might have been triggered by this though.

}

async unhideMarkupPreviews(cells: readonly MarkupCellViewModel[]) {
if (!this._webview) {
return;
Expand Down