diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.ts index c1b90d72e8ad6..8b068a1d13fdb 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.ts @@ -146,6 +146,10 @@ export class MarkupCell extends Disposable { this.foldingState = foldingState; this.layoutFoldingIndicator(); } + + // When folding state changes, we need to update the view to show/hide the preview + // This is important when restoring folding state on notebook open + this.viewUpdate(); } if (e.cellIsHoveredChanged) { @@ -412,6 +416,21 @@ export class MarkupCell extends Disposable { } } + // Check if the cell is inside a folded region - if so, hide the preview instead of creating it + // This handles the case where the preview was created before folding state was restored + // Note: Hidden ranges start at the first hidden cell (not the fold header), so >= is correct + const viewModel = this.notebookEditor.getViewModel(); + if (viewModel) { + const modelIndex = viewModel.getCellIndex(this.viewCell); + const foldedRanges = viewModel.getHiddenRanges(); + const isHidden = foldedRanges.some(range => modelIndex >= range.start && modelIndex <= range.end); + + if (isHidden) { + this.notebookEditor.hideMarkupPreviews([this.viewCell]); + return; + } + } + this.notebookEditor.createMarkupPreview(this.viewCell); }