Skip to content

Commit

Permalink
Fix scroll bars not appearing on certain settings
Browse files Browse the repository at this point in the history
Setting the bounds origins directly caused the scroll bar to not show up due to scroller management being hidden in `scroll(to: )`. This commit fixes that by canceling the animation after the call instead.
  • Loading branch information
nangtrongvuon committed Sep 24, 2019
1 parent 6677700 commit c504b10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Sources/XiEditor/EditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ class EditViewController: NSViewController, EditViewDataSource, FindDelegate, Sc
if first..<last != visibleLines {
document.sendWillScroll(first: first, last: last)
visibleLines = first..<last

// Cancels the scroll animation to prevent jerky scrolling.
scrollView.contentView.setBoundsOrigin(newOrigin)
}
editView.needsDisplay = true
}
Expand Down
7 changes: 1 addition & 6 deletions Sources/XiEditor/XiClipView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ 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.setBoundsOrigin(newOrigin)
super.scroll(to: newOrigin)
}
}

0 comments on commit c504b10

Please sign in to comment.