From cf108da37dc1dcf3f704383f36b06da4966d01e5 Mon Sep 17 00:00:00 2001 From: Igor Slobodskov Date: Wed, 16 Aug 2023 19:10:52 +0200 Subject: [PATCH] [DS-5493] compare Interval.language and type instead of just type GitOrigin-RevId: a42048d57f5e3f6d7f061ded1e2a9eaf6be95ca2 --- .../notebooks/visualization/NonIncrementalCellLines.kt | 4 +++- .../visualization/NotebookIntervalPointerImpl.kt | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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]