[PyCharm] PY-74366 Jupyter (feat): EditorComponentWrapper removed for RD needs.

It was added as some optimization in updating during scroll, but there is no need of it anymore.

GitOrigin-RevId: 9842fa4cd519efff0bc5fcefe23280c61f58a17e
This commit is contained in:
Nikita Pavlenko
2024-08-08 18:44:19 +00:00
committed by intellij-monorepo-bot
parent 4bc8e5b0c1
commit db375a8c52
@@ -8,7 +8,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.*
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.util.EditorScrollingPositionKeeper
import com.intellij.openapi.editor.impl.EditorComponentImpl
import com.intellij.openapi.fileEditor.FileEditorState
import com.intellij.openapi.fileEditor.FileEditorStateLevel
import com.intellij.openapi.fileEditor.TextEditor
@@ -18,7 +17,6 @@ import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.plugins.notebooks.ui.editor.actions.command.mode.NotebookEditorMode
import org.jetbrains.plugins.notebooks.ui.editor.actions.command.mode.setMode
import org.jetbrains.plugins.notebooks.visualization.*
import org.jetbrains.plugins.notebooks.visualization.inlay.JupyterBoundsChangeHandler
import org.jetbrains.plugins.notebooks.visualization.ui.EditorCellViewEventListener.CellViewRemoved
import org.jetbrains.plugins.notebooks.visualization.ui.EditorCellViewEventListener.EditorCellViewEvent
import java.awt.*
@@ -44,11 +42,9 @@ private class DecoratedEditor(private val original: TextEditor, private val mana
init {
if (!GraphicsEnvironment.isHeadless()) {
setupScrollPaneListener()
setupScrollPane()
}
setupEditorComponentWrapper()
manager.addCellViewEventsListener(object : EditorCellViewEventListener {
override fun onEditorCellViewEvents(events: List<EditorCellViewEvent>) {
events.asSequence().filterIsInstance<CellViewRemoved>().forEach {
@@ -121,9 +117,10 @@ private class DecoratedEditor(private val original: TextEditor, private val mana
return manager.cells.filter { it.interval.lines.hasIntersectionWith(lines) }
}
private fun setupScrollPaneListener() {
private fun setupScrollPane() {
val editorEx = original.editor as EditorEx
val scrollPane = editorEx.scrollPane
editorEx.scrollPane.viewport.isOpaque = false
scrollPane.viewport.addChangeListener {
editorEx.contentComponent.mousePosition?.let {
updateMouseOverCell(it)
@@ -138,14 +135,6 @@ private class DecoratedEditor(private val original: TextEditor, private val mana
return original.structureViewBuilder
}
private fun setupEditorComponentWrapper() {
val editorEx = original.editor as EditorEx
val scrollPane = editorEx.scrollPane
val view = scrollPane.viewport.view
scrollPane.viewport.isOpaque = false
scrollPane.viewport.view = EditorComponentWrapper(editorEx, view as EditorComponentImpl)
}
override fun getComponent(): JComponent = component
override fun getFile(): VirtualFile {
@@ -279,25 +268,6 @@ internal fun keepScrollingPositionWhile(editor: Editor, task: Runnable) {
}
}
class EditorComponentWrapper(
private val editor: Editor,
editorComponent: EditorComponentImpl,
) : JComponent() {
init {
isOpaque = false
layout = BorderLayout()
add(editorComponent, BorderLayout.CENTER)
}
override fun validateTree() {
keepScrollingPositionWhile(editor) {
JupyterBoundsChangeHandler.get(editor)?.postponeUpdates()
super.validateTree()
JupyterBoundsChangeHandler.get(editor)?.performPostponed()
}
}
}
/** lists assumed to be ordered and non-empty */
private fun hasIntersection(cells: List<NotebookCellLines.Interval>, others: List<NotebookCellLines.Interval>): Boolean =
!(cells.last().ordinal < others.first().ordinal || cells.first().ordinal > others.last().ordinal)