From bbec8974b134d89ca627e18dbee364b66f79cc81 Mon Sep 17 00:00:00 2001 From: Anton Efimchuk Date: Thu, 31 Oct 2024 14:23:36 +0100 Subject: [PATCH] PY-76779 [Jupyter] Fix switch scroll owner on mouse click (cherry picked from commit 47cd88d43e3b3ea1caef8be1f92048e875fe44b3) GitOrigin-RevId: 585900b8c3164e8d9ae6ad5cda19b2ef48e2f6bc --- .../notebooks/visualization/ui/DecoratedEditor.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/DecoratedEditor.kt b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/DecoratedEditor.kt index bcd04aaaea4b..9ec785e484d0 100644 --- a/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/DecoratedEditor.kt +++ b/notebooks/visualization/src/com/intellij/notebooks/visualization/ui/DecoratedEditor.kt @@ -16,6 +16,7 @@ import com.intellij.openapi.editor.ex.util.EditorScrollingPositionKeeper import com.intellij.openapi.editor.impl.EditorImpl import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.use +import com.intellij.ui.ComponentUtil import java.awt.BorderLayout import java.awt.Component import java.awt.GraphicsEnvironment @@ -24,9 +25,7 @@ import java.awt.event.InputEvent import java.awt.event.MouseEvent import java.awt.event.MouseWheelEvent import java.util.concurrent.atomic.AtomicBoolean -import javax.swing.JPanel -import javax.swing.JViewport -import javax.swing.SwingUtilities +import javax.swing.* import kotlin.math.max import kotlin.math.min @@ -103,7 +102,11 @@ class DecoratedEditor private constructor( } else if (event is MouseEvent) { if (event.id == MouseEvent.MOUSE_CLICKED || event.id == MouseEvent.MOUSE_RELEASED || event.id == MouseEvent.MOUSE_PRESSED) { - nestedScrollingSupport.processMouseEvent(event, editor.scrollPane) + ComponentUtil.getParentOfType(JScrollPane::class.java, (event.component as? JComponent) + ?.findComponentAt(event.point)) + ?.let { scrollPane -> + nestedScrollingSupport.processMouseEvent(event, scrollPane) + } } else if (event.id == MouseEvent.MOUSE_MOVED) { nestedScrollingSupport.processMouseMotionEvent(event)