diff --git a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NonIncrementalCellLines.kt b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NonIncrementalCellLines.kt index d2e3c73b1757..b4f090e34f94 100644 --- a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NonIncrementalCellLines.kt +++ b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NonIncrementalCellLines.kt @@ -53,7 +53,9 @@ class NonIncrementalCellLines private constructor(private val document: Document }.count() val trimAtEnd = oldCells.asReversed().zip(newCells.asReversed()).takeWhile { (oldCell, newCell) -> - oldCell.type == newCell.type && oldCell.size == newCell.size && + oldCell.type == newCell.type && + oldCell.language == newCell.language && + oldCell.size == newCell.size && oldCell != oldAffectedCells.lastOrNull() && newCell != newAffectedCells.lastOrNull() }.count() diff --git a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookIntervalPointerImpl.kt b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookIntervalPointerImpl.kt index 03a43fb0c07f..71324dec2106 100644 --- a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookIntervalPointerImpl.kt +++ b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookIntervalPointerImpl.kt @@ -206,6 +206,13 @@ class NotebookIntervalPointerFactoryImpl(private val notebookCellLines: Notebook private fun makeSnapshot(interval: NotebookCellLines.Interval) = PointerSnapshot(pointers[interval.ordinal], interval) + private fun hasSingleIntervalsWithSameTypeAndLanguage(oldIntervals: List, + newIntervals: List): Boolean { + val old = oldIntervals.singleOrNull() ?: return false + val new = newIntervals.singleOrNull() ?: return false + return old.type == new.type && old.language == new.language + } + private fun updateChangedIntervals(e: NotebookCellLinesEvent, eventChanges: NotebookIntervalPointersEventChanges) { when { !e.isIntervalsChanged() -> { @@ -214,7 +221,7 @@ class NotebookIntervalPointerFactoryImpl(private val notebookCellLines: Notebook eventChanges.add(OnEdited(pointers[editedInterval.ordinal], editedInterval, editedInterval)) } } - e.oldIntervals.size == 1 && e.newIntervals.size == 1 && e.oldIntervals.first().type == e.newIntervals.first().type -> { + hasSingleIntervalsWithSameTypeAndLanguage(e.oldIntervals, e.newIntervals) -> { // only one interval changed size for (editedInterval in e.newAffectedIntervals) { val ptr = pointers[editedInterval.ordinal]