terminal: simplify scrolling - now default TerminalPanel.handleMouseWheelEvent implementation works (IDEA-264105)

GitOrigin-RevId: f5acd70f31c5cf8b411a3ebfa3ce9f95281c69ad
This commit is contained in:
Sergey Simonchik
2021-03-22 11:03:23 +00:00
committed by intellij-monorepo-bot
parent 1e3079313b
commit 6c4e08a8a8
@@ -20,9 +20,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.ui.components.JBScrollBar;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.ui.scroll.TouchScrollUtil;
import com.intellij.util.JBHiDPIScaledImage;
import com.intellij.util.ui.ImageUtil;
import com.intellij.util.ui.JBUI;
@@ -132,54 +129,6 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Dis
return JBUI.emptySize();
}
@Override
protected void handleMouseWheelEvent(@NotNull MouseWheelEvent event, @NotNull JScrollBar scrollBar) {
// TODO replace with standard JBScrollPane in 2021.2 and remove this method!
if (event.isShiftDown() || event.getUnitsToScroll() == 0) return;
if (isNiceScrollingSupported(event)) {
MouseWheelEvent e = event;
if (Registry.is("idea.true.smooth.scrolling.pixel.perfect", true)) {
// Terminal's scrollBar.getModel() operates with lines, not pixel. So we need to covert back to units
// according to com.intellij.ui.components.JBScrollBar.getPreciseDelta implementation.
e = copyEventWithScaledRotation(event, JBUIScale.scale(10));
}
boolean handled = ((JBScrollBar)scrollBar).handleMouseWheelEvent(e);
if (!handled && LOG.isDebugEnabled()) {
LOG.debug("Mouse wheel event not handled");
}
}
else {
super.handleMouseWheelEvent(event, scrollBar);
}
}
private static boolean isNiceScrollingSupported(@NotNull MouseWheelEvent event) {
if (!isSupportedScrollType(event)) return false;
UISettings settings = UISettings.getInstanceOrNull();
return settings != null && settings.getSmoothScrolling();
}
private static boolean isSupportedScrollType(MouseWheelEvent e) {
return e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL || TouchScrollUtil.isUpdate(e);
}
private @NotNull MouseWheelEvent copyEventWithScaledRotation(@NotNull MouseWheelEvent e, int rotationScaleFactor) {
return new MouseWheelEvent(this,
e.getID(),
e.getWhen(),
e.getModifiers(),
e.getX(),
e.getY(),
e.getXOnScreen(),
e.getYOnScreen(),
e.getClickCount(),
e.isPopupTrigger(),
e.getScrollType(),
e.getScrollAmount(),
e.getWheelRotation() / rotationScaleFactor,
e.getPreciseWheelRotation() / rotationScaleFactor);
}
private boolean skipKeyEvent(@NotNull KeyEvent e) {
return skipAction(e, myActionsToSkip);
}