From c35775a4325685cf2970d59870e0d04da0ee7873 Mon Sep 17 00:00:00 2001 From: Dung Le Date: Mon, 24 Jun 2019 09:54:17 +0700 Subject: [PATCH] Fix janky scrolling on external mice This fixes an issue where the scroll(to: NSPoint) implementation only supports smooth scrolling and thus doesn't properly take into account notched mouse wheel scroll (which usually means external mice). --- Sources/XiEditor/XiClipView.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/XiEditor/XiClipView.swift b/Sources/XiEditor/XiClipView.swift index 1026a3dd..a1392a5d 100644 --- a/Sources/XiEditor/XiClipView.swift +++ b/Sources/XiEditor/XiClipView.swift @@ -21,8 +21,13 @@ protocol ScrollInterested: class { class XiClipView: NSClipView { weak var delegate: ScrollInterested? + // Smooth scrolling (like the MacBook trackpad or Apple Magic Mouse) sends scroll events that are chunked, continuous and cumulative, + // and thus the scroll view's clipView's bounds is set properly (in small increments) for each of these small chunks of scrolling. + // Scrolling with notched mice scrolls in discrete units, takes into account acceleration but does not redraw the view when the view is continuously redrawn (like in xi-mac) during scrolling. + // This is because the bounds origin is only set after the scrolling has stopped completely. + // We bypass this by simply setting the bound origin immediately. override func scroll(to newOrigin: NSPoint) { delegate?.willScroll(to: newOrigin) - super.scroll(to: newOrigin) + super.setBoundsOrigin(newOrigin) } }