Skip to content

Commit cec6f8d

Browse files
authored
Fix background markdown rendering issues (microsoft#153871)
This fixes background markdown rendering quitting after the first run, and running forever on folded cells, and rendering the last hidden item of the folded range. Fixes microsoft#151252
1 parent 0122f8b commit cec6f8d

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,22 +1153,25 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
11531153
const endTime = Date.now() + deadline.timeRemaining();
11541154

11551155
const execute = () => {
1156-
this._backgroundMarkdownRenderRunning = false;
1157-
if (this._isDisposed) {
1158-
return;
1159-
}
1156+
try {
1157+
this._backgroundMarkdownRenderRunning = true;
1158+
if (this._isDisposed) {
1159+
return;
1160+
}
11601161

1161-
if (!this.viewModel) {
1162-
return;
1163-
}
1162+
if (!this.viewModel) {
1163+
return;
1164+
}
11641165

1165-
const firstMarkupCell = this.viewModel.viewCells.find(cell => cell.cellKind === CellKind.Markup && !this._webview?.markupPreviewMapping.has(cell.id)) as MarkupCellViewModel | undefined;
1166-
if (!firstMarkupCell) {
1167-
return;
1168-
}
1166+
const firstMarkupCell = this.viewModel.viewCells.find(cell => cell.cellKind === CellKind.Markup && !this._webview?.markupPreviewMapping.has(cell.id) && !this.cellIsHidden(cell)) as MarkupCellViewModel | undefined;
1167+
if (!firstMarkupCell) {
1168+
return;
1169+
}
11691170

1170-
this._backgroundMarkdownRenderRunning = true;
1171-
this.createMarkupPreview(firstMarkupCell);
1171+
this.createMarkupPreview(firstMarkupCell);
1172+
} finally {
1173+
this._backgroundMarkdownRenderRunning = false;
1174+
}
11721175

11731176
if (Date.now() < endTime) {
11741177
setTimeout0(execute);
@@ -2564,10 +2567,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
25642567
return;
25652568
}
25662569

2567-
const modelIndex = this.viewModel.getCellIndex(cell);
2568-
const foldedRanges = this.viewModel.getHiddenRanges();
2569-
const isVisible = !foldedRanges.some(range => modelIndex >= range.start && modelIndex < range.end);
2570-
if (!isVisible) {
2570+
if (this.cellIsHidden(cell)) {
25712571
return;
25722572
}
25732573

@@ -2585,6 +2585,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
25852585
});
25862586
}
25872587

2588+
private cellIsHidden(cell: ICellViewModel): boolean {
2589+
const modelIndex = this.viewModel!.getCellIndex(cell);
2590+
const foldedRanges = this.viewModel!.getHiddenRanges();
2591+
return foldedRanges.some(range => modelIndex >= range.start && modelIndex <= range.end);
2592+
}
2593+
25882594
async unhideMarkupPreviews(cells: readonly MarkupCellViewModel[]) {
25892595
if (!this._webview) {
25902596
return;

0 commit comments

Comments
 (0)