Skip to content

Commit

Permalink
Fix janky scrolling on external mice
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
nangtrongvuon committed Jun 24, 2019
1 parent e6070e3 commit c35775a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/XiEditor/XiClipView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit c35775a

Please sign in to comment.