mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[Jupyter] Replace Flow with ObservableProperty
GitOrigin-RevId: 472aef73e1b7c65e8c3ad345a2aad3157d61549d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bdea992c1a
commit
b7bd47c0eb
@@ -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<NotebookCellInlayController.InputFactory>,
|
||||
private val cellExtensionFactories: List<CellExtensionFactory>,
|
||||
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<NotebookCellInlayController.InputFactory> = listOf(),
|
||||
cellExtensionFactories: List<CellExtensionFactory> = 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)
|
||||
|
||||
@@ -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<String>(getSource())
|
||||
val source = _source.asStateFlow()
|
||||
val source = AtomicProperty<String>(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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user