Skip to content

Commit d665222

Browse files
PY-89751 Restore cell rendering after collapse/expand of markdown headers
When a markdown header section is expanded, the previously hidden cell views are recreated but only their folding is set up (createCellView), so their outputs and inlays stay uninitialized until an unrelated event such as a scroll triggers NotebookVisibleCellsBatchUpdater. This is a regression from the lazy output initialization introduced in KTNB-812. Refresh a cell view right after it becomes visible again in updateCellVisibility (update + checkAndRebuildInlays + updateIfInVisibleRect) when the cell is inside the viewport, so an expanded section renders immediately. Cells outside the viewport keep being initialized lazily. The previous attempt added an isUnfolded listener on EditorCell that called updateIfInVisibleRect, but the cell view is always null at that point (it is disposed while folded and only recreated by NotebookCellInlayManager afterwards), so it was a no-op; it is removed. Add a deterministic regression test (JupyterMarkdownFoldingRenderingTest) that inspects the model right after the expand, and an end-to-end UI test in JupyterPolygonIPyKernelUiTest. M-Session-Id: M-b082df5b-7e57-46f6-aa59-496eef7d6cbe GitOrigin-RevId: ef66dc9979025f9d4f0df472f96e8c032465a3e5
1 parent 618c0bb commit d665222

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.intellij.notebooks.visualization.ui.EditorCellViewEventListener.CellV
1414
import com.intellij.notebooks.visualization.ui.EditorEmbeddedComponentContainer
1515
import com.intellij.notebooks.visualization.ui.EditorNotebook
1616
import com.intellij.notebooks.visualization.ui.JupyterCellSelectionNotifier
17+
import com.intellij.notebooks.visualization.ui.NotebookVisibleCellsBatchUpdater
1718
import com.intellij.notebooks.visualization.ui.endInlay.EditorNotebookEndInlay
1819
import com.intellij.notebooks.visualization.ui.endInlay.EditorNotebookEndInlayProvider
1920
import com.intellij.notebooks.visualization.ui.notebookViewUpdater
@@ -212,7 +213,18 @@ class NotebookCellInlayManager private constructor(
212213

213214
private fun updateCellVisibility(cell: EditorCell, visible: Boolean) = update { ctx ->
214215
if (visible) {
216+
val viewCreated = views[cell] == null
215217
createCellViewIfNecessary(cell, ctx)
218+
// A cell becomes visible again after its enclosing markdown section is expanded (PY-89751).
219+
// createCellView only sets up folding for the freshly recreated view, so its outputs and inlays stay
220+
// uninitialized until an unrelated event (such as a scroll) triggers NotebookVisibleCellsBatchUpdater.
221+
// Refresh the view right away when the cell is inside the viewport so the expanded section renders
222+
// immediately; cells outside the viewport keep being initialized lazily (KTNB-812).
223+
if (viewCreated && initialized.get() && NotebookVisibleCellsBatchUpdater.get(editor)?.isCellVisible(cell) == true) {
224+
cell.update(ctx)
225+
cell.checkAndRebuildInlays()
226+
cell.updateIfInVisibleRect()
227+
}
216228
}
217229
else {
218230
disposeCellView(cell)

notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCell.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class EditorCell(
3939
executionStatus.afterDistinctChange(this) {
4040
thisLogger().debug("Execution status changed: $it for interval ${intervalPointer.get()?.ordinal}")
4141
}
42-
43-
isUnfolded.afterDistinctChange(this) {
44-
if (isUnfolded.get()) {
45-
updateIfInVisibleRect()
46-
}
47-
}
4842
}
4943

5044
val cellFrameManager: EditorCellFrameManager? = EditorCellFrameManager.create(this)?.also {

0 commit comments

Comments
 (0)