diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt index 53fac1e5bd28..bf9e22ed3b50 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt @@ -17,11 +17,9 @@ import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Key import com.intellij.openapi.util.registry.Registry -import com.intellij.platform.util.coroutines.childScope import com.intellij.util.EventDispatcher import com.intellij.util.SmartList import com.intellij.util.concurrency.ThreadingAssertions -import kotlinx.coroutines.CoroutineScope import com.intellij.notebooks.ui.editor.actions.command.mode.NOTEBOOK_EDITOR_MODE import com.intellij.notebooks.ui.editor.actions.command.mode.NotebookEditorMode import com.intellij.notebooks.ui.editor.actions.command.mode.NotebookEditorModeListener @@ -38,9 +36,7 @@ class NotebookCellInlayManager private constructor( private val shouldCheckInlayOffsets: Boolean, private val inputFactories: List, private val cellExtensionFactories: List, - parentScope: CoroutineScope, ) : Disposable, NotebookIntervalPointerFactory.ChangeListener, NotebookEditorModeListener { - private val coroutineScope = parentScope.childScope("NotebookCellInlayManager") private val notebookCellLines = NotebookCellLines.get(editor) @@ -264,7 +260,7 @@ class NotebookCellInlayManager private constructor( } } - private fun createCell(interval: NotebookIntervalPointer) = EditorCell(editor, this, interval, coroutineScope) { cell -> + private fun createCell(interval: NotebookIntervalPointer) = EditorCell(editor, this, interval) { cell -> EditorCellView(editor, notebookCellLines, cell, this).also { Disposer.register(cell, it) } }.also { cellExtensionFactories.forEach { factory -> @@ -289,15 +285,13 @@ class NotebookCellInlayManager private constructor( shouldCheckInlayOffsets: Boolean, inputFactories: List = listOf(), cellExtensionFactories: List = listOf(), - parentScope: CoroutineScope, ) : NotebookCellInlayManager { EditorEmbeddedComponentContainer(editor as EditorEx) val notebookCellInlayManager = NotebookCellInlayManager( editor, shouldCheckInlayOffsets, inputFactories, - cellExtensionFactories, - parentScope + cellExtensionFactories ).also { Disposer.register(editor.disposable, it) } editor.putUserData(isFoldingEnabledKey, Registry.`is`("jupyter.editor.folding.cells")) NotebookIntervalPointerFactory.get(editor).changeListeners.addListener(notebookCellInlayManager, editor.disposable) diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCell.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCell.kt index 04946c48bf92..9b80e1a458e4 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCell.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCell.kt @@ -15,13 +15,6 @@ import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.observable.properties.AtomicProperty import com.intellij.openapi.util.* -import com.intellij.platform.util.coroutines.childScope -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.cancel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.launch import java.time.ZonedDateTime import kotlin.reflect.KClass @@ -31,14 +24,10 @@ class EditorCell( private val editor: EditorEx, val manager: NotebookCellInlayManager, var intervalPointer: NotebookIntervalPointer, - parentScope: CoroutineScope, private val viewFactory: (EditorCell) -> EditorCellView, ) : Disposable, UserDataHolder by UserDataHolderBase() { - private val coroutineScope = parentScope.childScope("EditorCell") - - private val _source = MutableStateFlow(getSource()) - val source = _source.asStateFlow() + val source = AtomicProperty(getSource()) private fun getSource(): String { val document = editor.document @@ -123,7 +112,6 @@ class EditorCell( override fun dispose() { cleanupExtensions() view?.let { disposeView(it) } - coroutineScope.cancel() } private fun cleanupExtensions() { @@ -143,10 +131,7 @@ class EditorCell( } fun updateInput() { - coroutineScope.launch(Dispatchers.Main) { - _source.emit(getSource()) - } - view?.updateInput() + source.set(getSource()) } fun onViewportChange() { diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCellView.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCellView.kt index 9c3a125bdf2b..f9606e4f5321 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCellView.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/EditorCellView.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.DataProvider import com.intellij.openapi.actionSystem.PlatformCoreDataKeys import com.intellij.openapi.actionSystem.PlatformDataKeys +import com.intellij.openapi.application.runInEdt import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.EditorKind @@ -86,6 +87,9 @@ class EditorCellView( } init { + cell.source.afterChange(this) { + updateInput() + } recreateControllers() updateSelection(false) updateOutputs() @@ -148,12 +152,12 @@ class EditorCellView( controllersToDispose.forEach { disposeController(it) } } - fun updateInput() { + private fun updateInput() = runInEdt { updateCellHighlight() input.updateInput() } - private fun updateOutputs() { + private fun updateOutputs() = runInEdt { if (hasOutputs()) { if (outputs == null) { outputs = EditorCellOutputs(editor, cell).also {