[PyCharm] Jupyter (fix): Fixed the wrong AboveCellDelimiterPanel when inserting the cell in the first position. #PY-85741 Ready For Merge

GitOrigin-RevId: 5f72dcab6916e56af1d2f0aeb307949202e49481
This commit is contained in:
Nikita Pavlenko
2025-12-23 13:02:12 +00:00
committed by intellij-monorepo-bot
parent 32ac344848
commit bdb10f6ce1
2 changed files with 17 additions and 11 deletions
@@ -354,7 +354,7 @@ class NotebookCellInlayManager private constructor(
return CELL_INLAY_MANAGER_KEY.get(editor)
}
val FOLDING_MARKER_KEY: Key<Boolean> = Key<Boolean>("jupyter.folding.paragraph")
val FOLDING_MARKER_KEY: Key<Boolean> = Key("jupyter.folding.paragraph")
private val CELL_INLAY_MANAGER_KEY = Key.create<NotebookCellInlayManager>(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 -> {
@@ -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<Change>) {
@@ -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<PointerSnapshot>) : 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<PointerSnapshot>) : 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