Skip to content

Instantly share code, notes, and snippets.

@zrzka
Last active July 31, 2020 21:58
Show Gist options
  • Save zrzka/3316be23624400f349ecc1de0a8d139d to your computer and use it in GitHub Desktop.
Save zrzka/3316be23624400f349ecc1de0a8d139d to your computer and use it in GitHub Desktop.
class ClipView: NSClipView {
var isScrollAnimationEnabled: Bool = true
override func scroll(to newOrigin: NSPoint) {
if isScrollAnimationEnabled {
super.scroll(to: newOrigin)
} else {
setBoundsOrigin(newOrigin)
}
}
}
class OutlineView: NSOutlineView {
private var arrowKeysDown = Set<UInt16>()
override func keyDown(with event: NSEvent) {
if (125...126).contains(event.keyCode) {
arrowKeysDown.insert(event.keyCode)
(enclosingScrollView?.contentView as? ClipView)?.isScrollAnimationEnabled = false
}
super.keyDown(with: event)
}
override func keyUp(with event: NSEvent) {
super.keyUp(with: event)
arrowKeysDown.remove(event.keyCode)
(enclosingScrollView?.contentView as? ClipView)?.isScrollAnimationEnabled = arrowKeysDown.isEmpty
}
}
@zrzka
Copy link
Author

zrzka commented Jul 31, 2020

Yeah, you're probably right, feel free to modify it in any way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment