This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor -scrollRectToVisible: out into a function.
- Loading branch information
Showing
5 changed files
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// RBLScrolling.h | ||
// Rebel | ||
// | ||
// Created by Rob Rix on 27/05/2014. | ||
// Copyright (c) 2014 GitHub. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
/// Scrolls `view`’s `enclosingScrollView` just enough to reveal `rect`, | ||
/// rather than scrolling it such that it lies in the middle of the new | ||
/// `visibleRect`. This resolves issues where scrolling quickly through | ||
/// long lists, e.g. by holding down the down arrow key in a table or | ||
/// outline view, will otherwise jump wildly around the scrollable | ||
/// region. | ||
BOOL RBLScrollRectInViewToVisible(NSView *view, NSRect rect); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// RBLScrolling.m | ||
// Rebel | ||
// | ||
// Created by Rob Rix on 27/05/2014. | ||
// Copyright (c) 2014 GitHub. All rights reserved. | ||
// | ||
|
||
#import "RBLScrolling.h" | ||
|
||
BOOL RBLScrollRectInViewToVisible(NSView *view, NSRect rect) { | ||
NSScrollView *scrollView = view.enclosingScrollView; | ||
NSRect visibleRect = view.visibleRect; | ||
|
||
void (^scrollToY)(CGFloat) = ^(CGFloat y) { | ||
NSPoint pointToScrollTo = NSMakePoint(0, y); | ||
|
||
[scrollView.contentView scrollToPoint:pointToScrollTo]; | ||
[scrollView reflectScrolledClipView:scrollView.contentView]; | ||
}; | ||
|
||
if (NSMinY(rect) < NSMinY(visibleRect)) { | ||
scrollToY(NSMinY(rect)); | ||
return YES; | ||
} | ||
|
||
if (NSMaxY(rect) > NSMaxY(visibleRect)) { | ||
scrollToY(NSMaxY(rect) - NSHeight(visibleRect)); | ||
return YES; | ||
} | ||
|
||
return NO; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters