@@ -172,33 +172,23 @@ public JEditTextArea(TextAreaDefaults defaults, InputHandler inputHandler) {
172172// focusedComponent = this;
173173
174174 addMouseWheelListener (e -> {
175- if (scrollBarsInitialized ) {
176- if (e .getScrollType () == MouseWheelEvent .WHEEL_UNIT_SCROLL ) {
177- int scrollAmount = e .getUnitsToScroll ();
178- // System.out.println("rot/amt = " + e.getWheelRotation() + " " + amt);
179- // int max = vertical.getMaximum();
180- // System.out.println("UNIT SCROLL of " + amt + " at value " + vertical.getValue() + " and max " + max);
181- // System.out.println(" get wheel rotation is " + e.getWheelRotation());
182- // int ex = e.getModifiersEx();
183- // String mods = InputEvent.getModifiersExText(ex);
184- // if (ex != 0) {
185- // System.out.println(" 3 2 1 0");
186- // System.out.println(" 10987654321098765432109876543210");
187- // System.out.println(" " + PApplet.binary(e.getModifiersEx()));
188- //// if (mods.length() > 0) {
189- // System.out.println(" mods extext = " + mods + " " + mods.length() + " " + PApplet.hex(mods.charAt(0)));
190- // }
191- // System.out.println(" " + e);
192-
193- // inertia scrolling on OS X will fire several shift-wheel events
194- // that are negative values.. this makes the scrolling area jump.
195- boolean isHorizontal = Platform .isMacOS () && e .isShiftDown ();
196- if (isHorizontal ) {
197- horizontal .setValue (horizontal .getValue () + scrollAmount );
198- }else {
199- vertical .setValue (vertical .getValue () + scrollAmount );
200- }
201- }
175+ if (!scrollBarsInitialized ) return ;
176+ if (e .getScrollType () != MouseWheelEvent .WHEEL_UNIT_SCROLL ) return ;
177+
178+ var smoothScrollAmount = e .getPreciseWheelRotation ();
179+ var isHorizontal = Platform .isMacOS () && e .isShiftDown ();
180+ if (isHorizontal ) {
181+ smoothHorizontal += smoothScrollAmount ;
182+ smoothHorizontal = Math .max (0 , smoothHorizontal );
183+ smoothHorizontal = Math .min (horizontal .getMaximum (), smoothHorizontal );
184+ painter .repaint ();
185+ horizontal .setValue ((int ) Math .round (smoothHorizontal ));
186+ }else {
187+ smoothVertical += smoothScrollAmount ;
188+ smoothVertical = Math .max (0 , smoothVertical );
189+ smoothVertical = Math .min (vertical .getMaximum (), smoothVertical );
190+ painter .repaint ();
191+ vertical .setValue ((int ) Math .round (smoothVertical ));
202192 }
203193 });
204194 }
@@ -286,6 +276,10 @@ public void setHorizontalScrollPosition(int what) {
286276 }
287277
288278
279+ public double getVerticalSmoothScrollPosition () {
280+ return smoothVertical ;
281+ }
282+
289283 /**
290284 * Returns the object responsible for painting this text area.
291285 */
@@ -2093,7 +2087,9 @@ public void processKeyEvent(KeyEvent event) {
20932087 protected int horizontalOffset ;
20942088
20952089 protected JScrollBar vertical ;
2090+ protected double smoothVertical ;
20962091 protected JScrollBar horizontal ;
2092+ protected double smoothHorizontal ;
20972093 protected boolean scrollBarsInitialized ;
20982094
20992095 protected InputHandler inputHandler ;
0 commit comments