diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt index 3ec4bad1fb57..2c8536c266e5 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt @@ -354,7 +354,7 @@ class NotebookCellInlayManager private constructor( return CELL_INLAY_MANAGER_KEY.get(editor) } - val FOLDING_MARKER_KEY: Key = Key("jupyter.folding.paragraph") + val FOLDING_MARKER_KEY: Key = Key("jupyter.folding.paragraph") private val CELL_INLAY_MANAGER_KEY = Key.create(NotebookCellInlayManager::class.java.name) } @@ -381,10 +381,16 @@ class NotebookCellInlayManager private constructor( change.subsequentPointers.forEach { addCell(it.pointer) } + //After insert, we need fix ranges of previous cell change.subsequentPointers.forEach { - val prevCell = getCellOrNull(it.interval.ordinal - 1) - prevCell?.checkAndRebuildInlays() + getCellOrNull(it.interval.ordinal - 1)?.checkAndRebuildInlays() + } + + // When we are inserting a new 'first cell', we need to update AboveCellDelimiterPanel + // for the old 'first' cell. + if (change.ordinals.contains(0)) { + getCellOrNull(change.ordinals.last + 1)?.checkAndRebuildInlays() } } is NotebookIntervalPointersEvent.OnRemoved -> { diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookIntervalPointersEvent.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookIntervalPointersEvent.kt index 8517de0b496d..0c3809be987c 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookIntervalPointersEvent.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookIntervalPointersEvent.kt @@ -1,12 +1,12 @@ package com.intellij.notebooks.visualization /** - * passed to [NotebookIntervalPointerFactory.ChangeListener] in next cases: - * * Underlying document is changed. (in such case cellLinesEvent != null) + * Passed to [NotebookIntervalPointerFactory.ChangeListener] in next cases: + * * Underlying document is changed. (in such cases cellLinesEvent != null) * * Someone explicitly swapped two pointers or invalidated them by calling [NotebookIntervalPointerFactory.modifyPointers] * * one of upper changes was reverted or redone. * - * Changes represented as list of trivial changes. [Change] + * Changes represented as a list of trivial changes. [Change] * Intervals which was just moved are not mentioned in changes. For example, when inserting code before them. */ data class NotebookIntervalPointersEvent(val isInBulkUpdate: Boolean,val changes: List) { @@ -15,17 +15,17 @@ data class NotebookIntervalPointersEvent(val isInBulkUpdate: Boolean,val changes data class PointerSnapshot(val pointer: NotebookIntervalPointer, val interval: NotebookCellLines.Interval) /** - * any change contains enough information to be inverted. It simplifies undo/redo actions. + * Any change contains enough information to be inverted. It simplifies undo/redo actions. */ sealed interface Change data class OnInserted(val subsequentPointers: List) : Change { - val ordinals = subsequentPointers.first().interval.ordinal..subsequentPointers.last().interval.ordinal + val ordinals: IntRange = subsequentPointers.first().interval.ordinal..subsequentPointers.last().interval.ordinal } - /* snapshots contains intervals before removal */ + /* Snapshots contain intervals before removal */ data class OnRemoved(val subsequentPointers: List) : Change { - val ordinals = subsequentPointers.first().interval.ordinal..subsequentPointers.last().interval.ordinal + val ordinals: IntRange = subsequentPointers.first().interval.ordinal..subsequentPointers.last().interval.ordinal } data class OnEdited(val pointer: NotebookIntervalPointer, @@ -35,7 +35,7 @@ data class NotebookIntervalPointersEvent(val isInBulkUpdate: Boolean,val changes get() = intervalAfter.ordinal } - /* snapshots contains intervals after swap */ + /* Snapshots contain intervals after swap */ data class OnSwapped(val first: PointerSnapshot, val second: PointerSnapshot) : Change { val firstOrdinal: Int get() = first.interval.ordinal