Revision: 15715
          http://sourceforge.net/p/skim-app/code/15715
Author:   hofman
Date:     2025-10-26 17:28:18 +0000 (Sun, 26 Oct 2025)
Log Message:
-----------
Move to next or previous page in horizontal layout when at the end of scrolling 
for Page Up/Down and Arrow Up/Down

Modified Paths:
--------------
    trunk/SKBasePDFView.m

Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m       2025-10-26 17:02:25 UTC (rev 15714)
+++ trunk/SKBasePDFView.m       2025-10-26 17:28:18 UTC (rev 15715)
@@ -396,25 +396,35 @@
     NSRect bounds = NSZeroRect;
     PDFPage *page = nil;
     
-    // Apple scrolls by too much, so correct for it
-    if (hasVerticalLayout(self)) {
+    if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+        page = [self currentPage];
+    } else if (hasVerticalLayout(self)) {
+        // Apple scrolls by too much, so correct for it
         scrollView = [self scrollView];
         clipView = [scrollView contentView];
         bounds = [clipView bounds];
-    } else if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
-        page = [self currentPage];
+    } else if (hasHorizontalLayout(self) && [self canGoToNextPage]) {
+        clipView = [[self scrollView] contentView];
+        bounds = [clipView bounds];
     }
     
     // always call super, as it also updates the current page
     [super scrollPageUp:sender];
     
-    // check whether our assumptions are still correct
-    if (clipView && [clipView isFlipped] == NO && NSMinY([clipView bounds]) < 
NSMinY(bounds)) {
-        CGFloat height = NSHeight(bounds) - [clipView contentInsets].top;
-        CGFloat bottom = NSMinY([[scrollView documentView] frame]);
-        bounds.origin.y = fmax(bottom, NSMinY(bounds) - fmax(height - 10.0, 
0.5 * height));
-        [clipView scrollToPoint:bounds.origin];
-        [scrollView reflectScrolledClipView:clipView];
+    if (scrollView) {
+        // check whether our assumptions are still correct
+        if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) < 
NSMinY(bounds)) {
+            CGFloat height = NSHeight(bounds) - [clipView contentInsets].top;
+            CGFloat bottom = NSMinY([[scrollView documentView] frame]);
+            bounds.origin.y = fmax(bottom, NSMinY(bounds) - fmax(height - 
10.0, 0.5 * height));
+            [clipView scrollToPoint:bounds.origin];
+            [scrollView reflectScrolledClipView:clipView];
+        }
+    } else if (clipView) {
+        if (fabs(NSMinY([clipView bounds]) - NSMinY(bounds)) <= 0.0) {
+            [self goToNextPage:sender];
+            [self verticallyScrollToTop];
+        }
     } else if (page && [[self currentPage] pageIndex] > [page pageIndex]) {
         // Apple scrolls to the bottom of the next page rather than the top
         [self verticallyScrollToTop];
@@ -428,25 +438,36 @@
     NSRect bounds = NSZeroRect;
     PDFPage *page = nil;
     
-    // Apple scrolls by too much, so correct for it
-    if (hasVerticalLayout(self)) {
+    if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+        page = [self currentPage];
+    } else if (hasVerticalLayout(self)) {
+        // Apple scrolls by too much, so correct for it
         scrollView = [self scrollView];
         clipView = [scrollView contentView];
         bounds = [clipView bounds];
-    } else if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
-        page = [self currentPage];
+    } else if (hasHorizontalLayout(self) && [self canGoToPreviousPage]) {
+        scrollView = [self scrollView];
+        clipView = [scrollView contentView];
+        bounds = [clipView bounds];
     }
     
     // always call super, as it also updates the current page
     [super scrollPageDown:sender];
     
-    // check whether our assumptions are still correct
-    if (clipView && [clipView isFlipped] == NO && NSMinY([clipView bounds]) > 
NSMinY(bounds)) {
-        CGFloat height = NSHeight(bounds) - [clipView contentInsets].top;
-        CGFloat top = NSMaxY([[scrollView documentView] frame]);
-        bounds.origin.y = fmin(top - height, NSMinY(bounds) + fmax(height - 
10.0, 0.5 * height));
-        [clipView scrollToPoint:bounds.origin];
-        [scrollView reflectScrolledClipView:clipView];
+    if (scrollView) {
+        // check whether our assumptions are still correct
+        if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) > 
NSMinY(bounds)) {
+            CGFloat height = NSHeight(bounds) - [clipView contentInsets].top;
+            CGFloat top = NSMaxY([[scrollView documentView] frame]);
+            bounds.origin.y = fmin(top - height, NSMinY(bounds) + fmax(height 
- 10.0, 0.5 * height));
+            [clipView scrollToPoint:bounds.origin];
+            [scrollView reflectScrolledClipView:clipView];
+        }
+    } else if (clipView) {
+        if (fabs(NSMinY([clipView bounds]) - NSMinY(bounds)) <= 0.0) {
+            [self goToPreviousPage:sender];
+            [self verticallyScrollToBottom];
+        }
     } else if (page && [[self currentPage] pageIndex] < [page pageIndex]) {
         // Apple scrolls to the top of the next page rather than the bottom
         [self verticallyScrollToBottom];
@@ -455,20 +476,50 @@
 
 // this is bound to ArrowDown in PDFView
 - (void)scrollLineUp:(id)sender {
-    PDFPage *page = ([self displayMode] & kPDFDisplaySinglePageContinuous) ? 
nil : [self currentPage];
+    NSClipView *clipView = nil;
+    NSRect bounds = NSZeroRect;
+    PDFPage *page = nil;
+    
+    if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+        page = [self currentPage];
+    } else if (hasHorizontalLayout(self) && [self canGoToNextPage]) {
+        clipView = [[self scrollView] contentView];
+        bounds = [clipView bounds];
+    }
+    
     [super scrollLineUp:sender];
-    // Apple scrolls to the bottom of the next page rather than the top
-    if (page && [[self currentPage] pageIndex] > [page pageIndex])
+    
+    if (clipView && fabs(NSMinY([clipView bounds]) - NSMinY(bounds)) <= 0.0) {
+        [self goToNextPage:sender];
         [self verticallyScrollToTop];
+    } else if (page && [[self currentPage] pageIndex] > [page pageIndex]) {
+        // Apple scrolls to the bottom of the next page rather than the top
+        [self verticallyScrollToTop];
+    }
 }
 
 // this is bound to ArrowUp in PDFView
 - (void)scrollLineDown:(id)sender {
-    PDFPage *page = ([self displayMode] & kPDFDisplaySinglePageContinuous) ? 
nil : [self currentPage];
+    NSClipView *clipView = nil;
+    NSRect bounds = NSZeroRect;
+    PDFPage *page = nil;
+    
+    if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
+        page = [self currentPage];
+    } else if (hasHorizontalLayout(self) && [self canGoToPreviousPage]) {
+        clipView = [[self scrollView] contentView];
+        bounds = [clipView bounds];
+    }
+    
     [super scrollLineDown:sender];
-    // Apple scrolls to the top of the next page rather than the bottom
-    if (page && [[self currentPage] pageIndex] < [page pageIndex])
+    
+    if (clipView && fabs(NSMinY([clipView bounds]) - NSMinY(bounds)) <= 0.0) {
+        [self goToPreviousPage:sender];
         [self verticallyScrollToBottom];
+    } else if (page && [[self currentPage] pageIndex] > [page pageIndex]) {
+        // Apple scrolls to the top of the next page rather than the bottom
+        [self verticallyScrollToBottom];
+    }
 }
 
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to