|
From: <ho...@us...> - 2025-10-24 17:30:54
|
Revision: 15702
http://sourceforge.net/p/skim-app/code/15702
Author: hofman
Date: 2025-10-24 17:30:53 +0000 (Fri, 24 Oct 2025)
Log Message:
-----------
Fix page navigation through scrolling, scroll to top of next page for Page/Line Down and to bottom of previous page for Page/Line Up (which are strangely bound to the opposite actions in PDFView)
Modified Paths:
--------------
trunk/SKBasePDFView.m
Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m 2025-10-23 16:50:47 UTC (rev 15701)
+++ trunk/SKBasePDFView.m 2025-10-24 17:30:53 UTC (rev 15702)
@@ -266,6 +266,42 @@
[scrollView reflectScrolledClipView:clipView];
}
+- (void)verticallyScrollToTop {
+ NSScrollView *scrollView = [self scrollView];
+ CGFloat inset = [scrollView contentInsets].top;
+ NSClipView *clipView = [scrollView contentView];
+ NSRect bounds = [clipView bounds];
+ NSView *docView = [scrollView documentView];
+ NSRect docRect = [docView convertRect:[docView bounds] toView:clipView];
+ inset = [self convertSize:NSMakeSize(0.0, inset) toView:clipView].height;
+ if (NSHeight(docRect) <= NSHeight(bounds) - inset)
+ return;
+ if ([clipView isFlipped])
+ bounds.origin.y = NSMinY(docRect) - inset;
+ else
+ bounds.origin.y = NSMaxY(docRect) - NSHeight(bounds) + inset;
+ [clipView scrollToPoint:bounds.origin];
+ [scrollView reflectScrolledClipView:clipView];
+}
+
+- (void)verticallyScrollToBottom {
+ NSScrollView *scrollView = [self scrollView];
+ CGFloat inset = [scrollView contentInsets].top;
+ NSClipView *clipView = [scrollView contentView];
+ NSRect bounds = [clipView bounds];
+ NSView *docView = [scrollView documentView];
+ NSRect docRect = [docView convertRect:[docView bounds] toView:clipView];
+ inset = [self convertSize:NSMakeSize(0.0, inset) toView:clipView].height;
+ if (NSHeight(docRect) <= NSHeight(bounds) - inset)
+ return;
+ if ([clipView isFlipped])
+ bounds.origin.y = NSMaxY(docRect) - NSHeight(bounds) - inset;
+ else
+ bounds.origin.y = NSMinY(docRect);
+ [clipView scrollToPoint:bounds.origin];
+ [scrollView reflectScrolledClipView:clipView];
+}
+
- (void)goToPreviousPage:(id)sender {
if (hasHorizontalLayout(self) && [self canGoToPreviousPage]) {
PDFDocument *doc = [self document];
@@ -363,6 +399,7 @@
NSClipView *clipView = nil;
NSRect bounds = NSZeroRect;
CGFloat bottom = 0.0;
+ PDFPage *page = nil;
// Apple scrolls by too much, so correct for it
if (hasVerticalLayout(self)) {
@@ -372,6 +409,8 @@
bounds = [clipView bounds];
NSView *docView = [self documentView];
bottom = NSMinY([docView convertRect:[docView bounds] toView:clipView]);
+ } else if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+ page = [self currentPage];
}
// always call super, as it also updates the current page
@@ -383,6 +422,8 @@
bounds.origin.y = fmax(bottom, NSMinY(bounds) - (height < 10.0 ? height : height < 20.0 ? 10.0 : height - 10.0));
[clipView scrollToPoint:bounds.origin];
[scrollView reflectScrolledClipView:clipView];
+ } else if (page && [[self currentPage] pageIndex] > [page pageIndex]) {
+ [self verticallyScrollToTop];
}
}
@@ -391,6 +432,7 @@
NSClipView *clipView = nil;
NSRect bounds = NSZeroRect;
CGFloat top = 0.0;
+ PDFPage *page = nil;
// Apple scrolls by too much, so correct for it
if (hasVerticalLayout(self)) {
@@ -399,6 +441,8 @@
bounds = [clipView bounds];
NSView *docView = [self documentView];
top = NSMaxY([docView convertRect:[docView bounds] toView:clipView]);
+ } else if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+ page = [self currentPage];
}
// always call super, as it also updates the current page
@@ -410,7 +454,23 @@
bounds.origin.y = fmin(top - height, NSMinY(bounds) + (height < 10.0 ? height : height < 20.0 ? 10.0 : height - 10.0));
[clipView scrollToPoint:bounds.origin];
[scrollView reflectScrolledClipView:clipView];
+ } else if (page && [[self currentPage] pageIndex] < [page pageIndex]) {
+ [self verticallyScrollToBottom];
}
}
+- (void)scrollLineUp:(id)sender {
+ PDFPage *page = ([self displayMode] & kPDFDisplaySinglePageContinuous) ? nil : [self currentPage];
+ [super scrollLineUp:sender];
+ if (page && [[self currentPage] pageIndex] > [page pageIndex])
+ [self verticallyScrollToTop];
+}
+
+- (void)scrollLineDown:(id)sender {
+ PDFPage *page = ([self displayMode] & kPDFDisplaySinglePageContinuous) ? nil : [self currentPage];
+ [super scrollLineDown:sender];
+ if (page && [[self currentPage] pageIndex] < [page pageIndex])
+ [self verticallyScrollToBottom];
+}
+
@end
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|