Revision: 14187
          http://sourceforge.net/p/skim-app/code/14187
Author:   hofman
Date:     2024-04-05 16:37:52 +0000 (Fri, 05 Apr 2024)
Log Message:
-----------
pass current page index as page hint for forward search

Modified Paths:
--------------
    trunk/SKMainDocument.m
    trunk/SKPDFSyncParser.m
    trunk/SKPDFSynchronizer.h
    trunk/SKPDFSynchronizer.m
    trunk/SKReadingBar.m
    trunk/SKSyncTeXParser.m

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKMainDocument.m      2024-04-05 16:37:52 UTC (rev 14187)
@@ -2013,7 +2013,7 @@
             source = [NSURL fileURLWithPath:source isDirectory:NO];
         else if ([source isKindOfClass:[NSURL class]] == NO)
             source = nil;
-        [[self synchronizer] findPageAndLocationForLine:[location 
integerValue] inFile:[source path] options:options];
+        [[self synchronizer] findPageAndLocationForLine:[location 
integerValue] inFile:[source path] fromPageIndex:[[[self pdfView] currentPage] 
pageIndex] options:options];
     } else {
         PDFSelection *selection = [PDFSelection 
selectionWithSpecifier:[[command arguments] objectForKey:@"To"]];
         if ([selection hasCharacters]) {

Modified: trunk/SKPDFSyncParser.m
===================================================================
--- trunk/SKPDFSyncParser.m     2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKPDFSyncParser.m     2024-04-05 16:37:52 UTC (rev 14187)
@@ -251,7 +251,7 @@
     return rv;
 }
 
-- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(NSString *)file {
+- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(NSString *)file 
fromPageIndex:(NSUInteger)pageIndex {
     BOOL rv = NO;
     NSArray *theLines = [lines objectForKey:file];
     if (theLines) {
@@ -259,7 +259,7 @@
         SKPDFSyncRecord *record = nil;
         SKPDFSyncRecord *beforeRecord = nil;
         SKPDFSyncRecord *afterRecord = nil;
-        SKPDFSyncRecord *atRecord = nil;
+        NSMutableArray *atRecords = [NSMutableArray array];
         
         for (record in theLines) {
             if ([record pageIndex] == NSNotFound)
@@ -271,13 +271,17 @@
                 afterRecord = record;
                 break;
             } else {
-                atRecord = record;
+                [atRecords addObject:record];
                 break;
             }
         }
         
-        if (atRecord) {
-            record = atRecord;
+        if ([atRecords count]) {
+            record = [atRecords firstObject];
+            for (SKPDFSyncRecord *atRecord in atRecords) {
+                if (ABS([atRecord pageIndex] - (NSInteger)pageIndex) < 
ABS([record pageIndex] - (NSInteger)pageIndex))
+                    record = atRecord;
+            }
         } else if (beforeRecord && afterRecord) {
             NSInteger beforeLine = [beforeRecord line];
             NSInteger afterLine = [afterRecord line];

Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h   2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKPDFSynchronizer.h   2024-04-05 16:37:52 UTC (rev 14187)
@@ -75,7 +75,7 @@
 @property (nullable, copy) NSString *fileName;
 
 - (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect 
pageBounds:(NSRect)bounds atPageIndex:(NSUInteger)pageIndex;
-- (void)findPageAndLocationForLine:(NSInteger)line inFile:(nullable NSString 
*)file options:(SKPDFSynchronizerOption)options;
+- (void)findPageAndLocationForLine:(NSInteger)line inFile:(nullable NSString 
*)file fromPageIndex:(NSUInteger)pageIndex 
options:(SKPDFSynchronizerOption)options;
 
 // this must be called to stop the DO server from running in the server thread
 - (void)terminate;
@@ -102,7 +102,7 @@
 - (void)enumerateSourceFilesUsingBlock:(void (^)(NSString *file))block;
 
 - (BOOL)findFile:(NSString * _Nullable __autoreleasing * _Nonnull)filePtr 
line:(NSInteger *)linePtr forLocation:(NSPoint)point inRect:(NSRect)rect 
pageBounds:(NSRect)bounds atPageIndex:(NSUInteger)pageIndex;
-- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(nullable NSString *)file;
+- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(nullable NSString *)file 
fromPageIndex:(NSUInteger)pageIndex;
 
 @end
 

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKPDFSynchronizer.m   2024-04-05 16:37:52 UTC (rev 14187)
@@ -228,7 +228,7 @@
     });
 }
 
-- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file 
options:(SKPDFSynchronizerOption)options {
+- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file 
fromPageIndex:(NSUInteger)pageIndex options:(SKPDFSynchronizerOption)options {
     if (file == nil)
         file = [self defaultSourceFile];
     dispatch_async(queue, ^{
@@ -249,7 +249,7 @@
                 if (sourceFile == nil)
                     sourceFile = [fixedFile lastPathComponent];
             }
-            success = [parser findPage:&foundPageIndex location:&foundPoint 
forLine:line inFile:sourceFile];
+            success = [parser findPage:&foundPageIndex location:&foundPoint 
forLine:line inFile:sourceFile fromPageIndex:0];
             
             if (success && atomic_load(&shouldKeepRunning)) {
                 if (isPdfsync)

Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m        2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKReadingBar.m        2024-04-05 16:37:52 UTC (rev 14187)
@@ -320,7 +320,7 @@
         SKPDFSynchronizerOption options = SKPDFSynchronizerShowReadingBarMask;
         if ([[args objectForKey:@"Selecting"] boolValue])
             options |= SKPDFSynchronizerSelectMask;
-        [[(SKMainDocument *)[page containingDocument] synchronizer] 
findPageAndLocationForLine:[location integerValue] inFile:[source path] 
options:options];
+        [[(SKMainDocument *)[page containingDocument] synchronizer] 
findPageAndLocationForLine:[location integerValue] inFile:[source path] 
fromPageIndex:[page pageIndex] options:options];
         return;
     } else {
         PDFSelection *selection = [[[PDFSelection 
selectionWithSpecifier:[[command arguments] objectForKey:@"To"]] 
selectionsByLine] firstObject];

Modified: trunk/SKSyncTeXParser.m
===================================================================
--- trunk/SKSyncTeXParser.m     2024-04-05 15:30:10 UTC (rev 14186)
+++ trunk/SKSyncTeXParser.m     2024-04-05 16:37:52 UTC (rev 14187)
@@ -91,10 +91,10 @@
     return rv;
 }
 
-- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(NSString *)file {
+- (BOOL)findPage:(NSUInteger *)pageIndexPtr location:(NSPoint *)pointPtr 
forLine:(NSInteger)line inFile:(NSString *)file 
fromPageIndex:(NSUInteger)pageIndex  {
     BOOL rv = NO;
     const char *filename = [file UTF8String];
-    if (synctex_display_query(scanner, filename, (int)line + 1, 0, -1) > 0) {
+    if (synctex_display_query(scanner, filename, (int)line + 1, 0, pageIndex) 
> 0) {
         synctex_node_p node = synctex_scanner_next_result(scanner);
         if (node) {
             NSUInteger page = synctex_node_page(node);

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