From 158e70ea4dea01666d59b0988323e04b951f3ecb Mon Sep 17 00:00:00 2001 From: Bogdan Kirilenko Date: Mon, 11 Nov 2024 12:02:03 +0100 Subject: [PATCH] [PyCharm] PY-77218 Jupyter bugfix - don't show add cells toolbar at the end of the console + minor refactoring (cherry picked from commit bff263fb3c7131180d80e44cae52f9ff39fc27c3) GitOrigin-RevId: ebf47b6024e1178a6d9b2fb3421285a3761856b0 --- .../visualization/NotebookCellInlayManager.kt | 20 +++++++++++++++++++ .../visualization/ui/NotebookEditorUiUtil.kt | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt index f31eb84f4c59..1103c6820a8a 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/NotebookCellInlayManager.kt @@ -2,6 +2,7 @@ package com.intellij.notebooks.visualization import com.intellij.ide.ui.LafManagerListener import com.intellij.notebooks.ui.isFoldingEnabledKey +import com.intellij.notebooks.ui.visualization.NotebookBelowLastCellPanel import com.intellij.notebooks.visualization.inlay.JupyterBoundsChangeHandler import com.intellij.notebooks.visualization.ui.* import com.intellij.notebooks.visualization.ui.EditorCellEventListener.* @@ -23,6 +24,7 @@ import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.ex.FoldingListener import com.intellij.openapi.editor.ex.FoldingModelEx import com.intellij.openapi.editor.impl.EditorImpl +import com.intellij.openapi.editor.Inlay import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Key import com.intellij.openapi.util.registry.Registry @@ -48,6 +50,8 @@ class NotebookCellInlayManager private constructor( val views = mutableMapOf() + private var belowLastCellInlay: Inlay<*>? = null + /** * Listens for inlay changes (called after all inlays are updated). Feel free to convert it to the EP if you need another listener */ @@ -183,6 +187,7 @@ class NotebookCellInlayManager private constructor( setupFoldingListener() setupSelectionUI() + addBelowLastCellInlay() cellEventListeners.addListener(object : EditorCellEventListener { override fun onEditorCellEvents(events: List) { @@ -275,6 +280,21 @@ class NotebookCellInlayManager private constructor( } } + private fun addBelowLastCellInlay() { // PY-77218 + belowLastCellInlay = editor.addComponentInlay( + NotebookBelowLastCellPanel(editor), + isRelatedToPrecedingText = true, + showAbove = false, + priority = 0, + offset = editor.document.getLineEndOffset((editor.document.lineCount - 1).coerceAtLeast(0)) + ) + } + + fun removeBelowLastCellInlay() { + belowLastCellInlay?.dispose() + belowLastCellInlay = null + } + private fun setupFoldingListener() { val foldingModel = editor.foldingModel foldingModel.addListener(object : FoldingListener { diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/NotebookEditorUiUtil.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/NotebookEditorUiUtil.kt index b5e50fb41875..3bfb0fc72d9a 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/NotebookEditorUiUtil.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/NotebookEditorUiUtil.kt @@ -1,6 +1,5 @@ package com.intellij.notebooks.visualization.ui -import com.intellij.openapi.application.ReadAction import com.intellij.openapi.application.WriteIntentReadAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.EditorKind