[PyCharm] Jupyter (fix): Reworked command and edit mode behavior for Markdown cells. (#PY-76244, #PY-76245 #PY-75855, #PY-76159) Fixed

GitOrigin-RevId: 4938b2a9c624d7de704b6139dbf7a7c78ff98425
This commit is contained in:
Nikita Pavlenko
2024-09-26 15:13:15 +02:00
committed by intellij-monorepo-bot
parent 43ec6e748d
commit 225b86c836
4 changed files with 29 additions and 20 deletions

View File

@@ -0,0 +1,12 @@
package com.intellij.notebooks.ui
/**
* We have global IdeEventQueue.getInstance().addDispatcher listener [SelectClickedCellEventDispatcher], which process every mouse
* click for the whole app and selects cell under mouse.
*
* We can use SKIP_CLICK_PROCESSING_FOR_CELL_SELECTION flag to stop click processing for our over-the-cell component,
* to prevent cell clicking.
*/
object SelectClickedCellEventHelper {
const val SKIP_CLICK_PROCESSING_FOR_CELL_SELECTION: String = "SkipClickProcessingForCellSelection"
}

View File

@@ -1,5 +1,6 @@
package com.intellij.notebooks.ui.jupyterToolbar
import com.intellij.notebooks.ui.SelectClickedCellEventHelper
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl
@@ -32,10 +33,10 @@ class JupyterAddNewCellToolbar(
isOpaque = false
cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
targetComponent = target
putClientProperty(SelectClickedCellEventHelper.SKIP_CLICK_PROCESSING_FOR_CELL_SELECTION, true)
setSkipWindowAdjustments(false)
}
override fun paintComponent(g: Graphics) {
val g2 = g.create() as Graphics2D
try {

View File

@@ -29,15 +29,6 @@ class EditorCell(
val source = AtomicProperty<String>(getSource())
private fun getSource(): String {
val document = editor.document
if (interval.lines.first + 1 >= document.lineCount) return ""
val startOffset = document.getLineStartOffset(interval.lines.first + 1)
val endOffset = document.getLineEndOffset(interval.lines.last)
if (startOffset >= endOffset) return "" // possible for empty cells
return document.getText(TextRange(startOffset, endOffset))
}
val type = interval.type
val interval get() = intervalPointer.get() ?: error("Invalid interval")
@@ -47,20 +38,30 @@ class EditorCell(
var visible = AtomicBooleanProperty(true)
init {
CELL_EXTENSION_CONTAINER_KEY.set(this, mutableMapOf())
}
val selected = AtomicBooleanProperty(false)
val gutterAction = AtomicProperty<AnAction?>(null)
val executionStatus = AtomicProperty<ExecutionStatus>(ExecutionStatus())
// ToDo we should remove or rework this. Mode does not really reflects the state of markdown cells.
val mode = AtomicProperty<NotebookEditorMode>(NotebookEditorMode.COMMAND)
val outputs = AtomicProperty<List<NotebookOutputDataKey>>(getOutputs())
init {
CELL_EXTENSION_CONTAINER_KEY.set(this, mutableMapOf())
}
private fun getSource(): String {
val document = editor.document
if (interval.lines.first + 1 >= document.lineCount) return ""
val startOffset = document.getLineStartOffset(interval.lines.first + 1)
val endOffset = document.getLineEndOffset(interval.lines.last)
if (startOffset >= endOffset) return "" // possible for empty cells
return document.getText(TextRange(startOffset, endOffset))
}
override fun dispose() {
cleanupExtensions()
}
@@ -187,6 +188,6 @@ class EditorCell(
val status: ProgressStatus? = null,
val count: Int? = null,
val startTime: ZonedDateTime? = null,
val endTime: ZonedDateTime? = null
val endTime: ZonedDateTime? = null,
)
}

View File

@@ -1,5 +0,0 @@
package com.intellij.notebooks.visualization.ui
object SelectClickedCellEventHelper {
const val SKIP_CLICK_PROCESSING_FOR_CELL_SELECTION: String = "SkipClickProcessingForCellSelection"
}