Revision: 15743
          http://sourceforge.net/p/skim-app/code/15743
Author:   hofman
Date:     2025-11-01 17:46:01 +0000 (Sat, 01 Nov 2025)
Log Message:
-----------
Check whether Apple uses the expected scroll a tions for the various keys, and 
correct accordingly

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

Modified: trunk/SKBasePDFView.h
===================================================================
--- trunk/SKBasePDFView.h       2025-11-01 17:18:36 UTC (rev 15742)
+++ trunk/SKBasePDFView.h       2025-11-01 17:46:01 UTC (rev 15743)
@@ -44,6 +44,7 @@
 
 @interface SKBasePDFView : PDFView {
     NSInteger minHistoryIndex;
+    NSInteger keyDirection;
 }
 
 - (void)colorFiltersDidChange;

Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m       2025-11-01 17:18:36 UTC (rev 15742)
+++ trunk/SKBasePDFView.m       2025-11-01 17:46:01 UTC (rev 15743)
@@ -40,6 +40,7 @@
 #import "SKStringConstants.h"
 #import "NSGeometry_SKExtensions.h"
 #import "NSGraphics_SKExtensions.h"
+#import "NSEvent_SKExtensions.h"
 #import "PDFAnnotation_SKExtensions.h"
 #import "PDFPage_SKExtensions.h"
 #import "PDFDestination_SKExtensions.h"
@@ -389,6 +390,18 @@
     [super goToDestination:destination];
 }
 
+- (void)keyDown:(NSEvent *)event {
+    unichar ch = [event firstCharacter];
+    if (ch == NSPageDownFunctionKey || ch == NSDownArrowFunctionKey)
+        keyDirection = 1;
+    else if (ch == NSPageUpFunctionKey || ch == NSUpArrowFunctionKey)
+        keyDirection = -1;
+    else if (ch == SKSpaceCharacter)
+        keyDirection = ([event modifierFlags] & NSEventModifierFlagShift) ? -1 
: 1;
+    [super keyDown:event];
+    keyDirection = 0;
+}
+
 // this is bound to PageDown in PDFView
 - (void)scrollPageUp:(id)sender {
     NSScrollView *scrollView = nil;
@@ -403,7 +416,7 @@
         scrollView = [self scrollView];
         clipView = [scrollView contentView];
         bounds = [clipView bounds];
-    } else if (hasHorizontalLayout(self) && [self canGoToNextPage]) {
+    } else if (hasHorizontalLayout(self) && (keyDirection == -1 ? [self 
canGoToPreviousPage] : [self canGoToNextPage])) {
         clipView = [[self scrollView] contentView];
         bounds = [clipView bounds];
     }
@@ -412,25 +425,48 @@
     [super scrollPageUp:sender];
     
     if (scrollView) {
-        CGFloat height = NSHeight(bounds) - [clipView contentInsets].top;
+        CGFloat inset = [clipView contentInsets].top;
+        CGFloat height = NSHeight(bounds) - inset;
         CGFloat offset = fmax(height - [scrollView verticalPageScroll], 0.5 * 
height);
-        // check whether our assumptions are still correct
-        if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) < 
NSMinY(bounds))
-            bounds.origin.y = fmax(NSMinY([[scrollView documentView] frame]), 
NSMinY(bounds) - offset);
-        else if ([clipView isFlipped] && NSMinY([clipView bounds]) > 
NSMinY(bounds))
-            bounds.origin.y = fmin(NSMaxY([[scrollView documentView] frame]) - 
NSHeight(bounds), NSMinY(bounds) + offset);
-        else
-            return;
+        if (keyDirection == -1) {
+            // check whether our assumptions are still correct
+            if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) > 
NSMinY(bounds))
+                bounds.origin.y = fmin(NSMaxY([[scrollView documentView] 
frame]) - height, NSMinY(bounds) + offset);
+            else if ([clipView isFlipped] && NSMinY([clipView bounds]) < 
NSMinY(bounds))
+                bounds.origin.y = fmax(NSMinY([[scrollView documentView] 
frame]) - inset, NSMinY(bounds) - offset);
+            else
+                return;
+        } else {
+            // check whether our assumptions are still correct
+            if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) < 
NSMinY(bounds))
+                bounds.origin.y = fmax(NSMinY([[scrollView documentView] 
frame]), NSMinY(bounds) - offset);
+            else if ([clipView isFlipped] && NSMinY([clipView bounds]) > 
NSMinY(bounds))
+                bounds.origin.y = fmin(NSMaxY([[scrollView documentView] 
frame]) - NSHeight(bounds), NSMinY(bounds) + offset);
+            else
+                return;
+        }
         [clipView scrollToPoint:bounds.origin];
         [scrollView reflectScrolledClipView:clipView];
     } else if (clipView) {
         if (NSEqualPoints([clipView bounds].origin, bounds.origin)) {
-            [self goToNextPage:sender];
-            [self verticallyScrollToTop];
+            if (keyDirection == -1) {
+                [self goToPreviousPage:sender];
+                [self verticallyScrollToBottom];
+            } else {
+                [self goToNextPage:sender];
+                [self verticallyScrollToTop];
+            }
         }
-    } else if (page && [[self currentPage] pageIndex] > [page pageIndex]) {
-        // Apple scrolls to the bottom of the previous page rather than the top
-        [self verticallyScrollToTop];
+    } else if (page) {
+        if (keyDirection == -1) {
+            // Apple scrolls to the top of the next page rather than the bottom
+            if ([[self currentPage] pageIndex] < [page pageIndex])
+                [self verticallyScrollToBottom];
+        } else {
+            // Apple scrolls to the bottom of the previous page rather than 
the top
+            if ([[self currentPage] pageIndex] > [page pageIndex])
+                [self verticallyScrollToTop];
+        }
     }
 }
 
@@ -448,7 +484,7 @@
         scrollView = [self scrollView];
         clipView = [scrollView contentView];
         bounds = [clipView bounds];
-    } else if (hasHorizontalLayout(self) && [self canGoToPreviousPage]) {
+    } else if (hasHorizontalLayout(self) && (keyDirection == 1 ? [self 
canGoToNextPage] : [self canGoToPreviousPage])) {
         clipView = [[self scrollView] contentView];
         bounds = [clipView bounds];
     }
@@ -460,23 +496,45 @@
         CGFloat inset = [clipView contentInsets].top;
         CGFloat height = NSHeight(bounds) - inset;
         CGFloat offset = fmax(height - [scrollView verticalPageScroll], 0.5 * 
height);
-        // check whether our assumptions are still correct
-        if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) > 
NSMinY(bounds))
-            bounds.origin.y = fmin(NSMaxY([[scrollView documentView] frame]) - 
height, NSMinY(bounds) + offset);
-        else if ([clipView isFlipped] && NSMinY([clipView bounds]) < 
NSMinY(bounds))
-            bounds.origin.y = fmax(NSMinY([[scrollView documentView] frame]) - 
inset, NSMinY(bounds) - offset);
-        else
-            return;
+        if (keyDirection == 1) {
+            // check whether our assumptions are still correct
+            if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) < 
NSMinY(bounds))
+                bounds.origin.y = fmax(NSMinY([[scrollView documentView] 
frame]), NSMinY(bounds) - offset);
+            else if ([clipView isFlipped] && NSMinY([clipView bounds]) > 
NSMinY(bounds))
+                bounds.origin.y = fmin(NSMaxY([[scrollView documentView] 
frame]) - NSHeight(bounds), NSMinY(bounds) + offset);
+            else
+                return;
+        } else {
+            // check whether our assumptions are still correct
+            if ([clipView isFlipped] == NO && NSMinY([clipView bounds]) > 
NSMinY(bounds))
+                bounds.origin.y = fmin(NSMaxY([[scrollView documentView] 
frame]) - height, NSMinY(bounds) + offset);
+            else if ([clipView isFlipped] && NSMinY([clipView bounds]) < 
NSMinY(bounds))
+                bounds.origin.y = fmax(NSMinY([[scrollView documentView] 
frame]) - inset, NSMinY(bounds) - offset);
+            else
+                return;
+        }
         [clipView scrollToPoint:bounds.origin];
         [scrollView reflectScrolledClipView:clipView];
     } else if (clipView) {
         if (NSEqualPoints([clipView bounds].origin, bounds.origin)) {
-            [self goToPreviousPage:sender];
-            [self verticallyScrollToBottom];
+            if (keyDirection == 1) {
+                [self goToNextPage:sender];
+                [self verticallyScrollToTop];
+            } else {
+                [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];
+    } else if (page) {
+        if (keyDirection == 1) {
+            // Apple scrolls to the bottom of the previous page rather than 
the top
+            if ([[self currentPage] pageIndex] > [page pageIndex])
+                [self verticallyScrollToTop];
+        } else {
+            // Apple scrolls to the top of the next page rather than the bottom
+            if ([[self currentPage] pageIndex] < [page pageIndex])
+                [self verticallyScrollToBottom];
+        }
     }
 }
 
@@ -488,7 +546,7 @@
     
     if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
         page = [self currentPage];
-    } else if (hasHorizontalLayout(self) && [self canGoToNextPage]) {
+    } else if (hasHorizontalLayout(self) && (keyDirection == -1 ? [self 
canGoToPreviousPage] : [self canGoToNextPage])) {
         clipView = [[self scrollView] contentView];
         bounds = [clipView bounds];
     }
@@ -496,11 +554,23 @@
     [super scrollLineUp:sender];
     
     if (clipView && NSEqualPoints([clipView bounds].origin, bounds.origin)) {
-        [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];
+        if (keyDirection == -1) {
+            [self goToPreviousPage:sender];
+            [self verticallyScrollToBottom];
+        } else {
+            [self goToNextPage:sender];
+            [self verticallyScrollToTop];
+        }
+    } else if (page) {
+        if (keyDirection == -1) {
+            // Apple scrolls to the top of the previous page rather than the 
bottom
+            if ([[self currentPage] pageIndex] < [page pageIndex])
+                [self verticallyScrollToBottom];
+        } else {
+            // Apple scrolls to the bottom of the next page rather than the top
+            if ([[self currentPage] pageIndex] > [page pageIndex])
+                [self verticallyScrollToTop];
+        }
     }
 }
 
@@ -512,7 +582,7 @@
     
     if (([self displayMode] & kPDFDisplaySinglePageContinuous) == 0) {
         page = [self currentPage];
-    } else if (hasHorizontalLayout(self) && [self canGoToPreviousPage]) {
+    } else if (hasHorizontalLayout(self) && (keyDirection == 1 ? [self 
canGoToNextPage] : [self canGoToPreviousPage])) {
         clipView = [[self scrollView] contentView];
         bounds = [clipView bounds];
     }
@@ -520,11 +590,23 @@
     [super scrollLineDown:sender];
     
     if (clipView && NSEqualPoints([clipView bounds].origin, bounds.origin)) {
-        [self goToPreviousPage:sender];
-        [self verticallyScrollToBottom];
-    } else if (page && [[self currentPage] pageIndex] < [page pageIndex]) {
-        // Apple scrolls to the top of the previous page rather than the bottom
-        [self verticallyScrollToBottom];
+        if (keyDirection == 1) {
+            [self goToNextPage:sender];
+            [self verticallyScrollToTop];
+        } else {
+            [self goToPreviousPage:sender];
+            [self verticallyScrollToBottom];
+        }
+    } else if (page) {
+        if (keyDirection == 1) {
+            // Apple scrolls to the bottom of the next page rather than the top
+            if ([[self currentPage] pageIndex] > [page pageIndex])
+                [self verticallyScrollToTop];
+        } else {
+            // Apple scrolls to the top of the previous page rather than the 
bottom
+            if ([[self currentPage] pageIndex] < [page pageIndex])
+                [self verticallyScrollToBottom];
+        }
     }
 }
 

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