Revision: 7643
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7643&view=rev
Author:   hofman
Date:     2012-02-13 22:14:53 +0000 (Mon, 13 Feb 2012)
Log Message:
-----------
Order search results when adding, because they are not always returned in the 
right order

Modified Paths:
--------------
    trunk/NSGeometry_SKExtensions.h
    trunk/NSGeometry_SKExtensions.m
    trunk/NSValue_SKExtensions.m
    trunk/SKGroupedSearchResult.m
    trunk/SKMainWindowController.m

Modified: trunk/NSGeometry_SKExtensions.h
===================================================================
--- trunk/NSGeometry_SKExtensions.h     2012-02-13 17:01:51 UTC (rev 7642)
+++ trunk/NSGeometry_SKExtensions.h     2012-02-13 22:14:53 UTC (rev 7643)
@@ -157,6 +157,10 @@
 
 #pragma mark -
 
+extern NSComparisonResult SKCompareRects(NSRect rect1, NSRect rect2);
+
+#pragma mark -
+
 static inline
 Rect SKQDRectFromNSRect(NSRect nsRect) {
     Rect qdRect;

Modified: trunk/NSGeometry_SKExtensions.m
===================================================================
--- trunk/NSGeometry_SKExtensions.m     2012-02-13 17:01:51 UTC (rev 7642)
+++ trunk/NSGeometry_SKExtensions.m     2012-02-13 22:14:53 UTC (rev 7643)
@@ -140,3 +140,23 @@
     else
         return 0;
 }
+
+NSComparisonResult SKCompareRects(NSRect rect1, NSRect rect2) {
+    CGFloat top1 = NSMaxY(rect1);
+    CGFloat top2 = NSMaxY(rect2);
+    
+    if (top1 > top2)
+        return NSOrderedAscending;
+    else if (top1 < top2)
+        return NSOrderedDescending;
+    
+    CGFloat left1 = NSMinX(rect1);
+    CGFloat left2 = NSMinX(rect2);
+    
+    if (left1 < left2)
+        return NSOrderedAscending;
+    else if (left1 > left2)
+        return NSOrderedDescending;
+    else
+        return NSOrderedSame;
+}

Modified: trunk/NSValue_SKExtensions.m
===================================================================
--- trunk/NSValue_SKExtensions.m        2012-02-13 17:01:51 UTC (rev 7642)
+++ trunk/NSValue_SKExtensions.m        2012-02-13 22:14:53 UTC (rev 7643)
@@ -37,30 +37,13 @@
  */
 
 #import "NSValue_SKExtensions.h"
+#import "NSGeometry_SKExtensions.h"
 
 
 @implementation NSValue (SKExtensions)
 
 - (NSComparisonResult)boundsCompare:(NSValue *)aValue {
-    NSRect rect1 = [self rectValue];
-    NSRect rect2 = [aValue rectValue];
-    CGFloat top1 = NSMaxY(rect1);
-    CGFloat top2 = NSMaxY(rect2);
-    
-    if (top1 > top2)
-        return NSOrderedAscending;
-    else if (top1 < top2)
-        return NSOrderedDescending;
-    
-    CGFloat left1 = NSMinX(rect1);
-    CGFloat left2 = NSMinX(rect2);
-    
-    if (left1 < left2)
-        return NSOrderedAscending;
-    else if (left1 > left2)
-        return NSOrderedDescending;
-    else
-        return NSOrderedSame;
+    return SKCompareRects([self rectValue], [aValue rectValue]);
 }
 
 - (NSString *)rectString {

Modified: trunk/SKGroupedSearchResult.m
===================================================================
--- trunk/SKGroupedSearchResult.m       2012-02-13 17:01:51 UTC (rev 7642)
+++ trunk/SKGroupedSearchResult.m       2012-02-13 22:14:53 UTC (rev 7643)
@@ -37,6 +37,8 @@
  */
 
 #import "SKGroupedSearchResult.h"
+#import "PDFPage_SKExtensions.h"
+#import "NSGeometry_SKExtensions.h"
 
 NSString *SKGroupedSearchResultCountKey = @"count";
 
@@ -71,7 +73,13 @@
 
 - (void)addMatch:(PDFSelection *)match {
     [self willChangeValueForKey:SKGroupedSearchResultCountKey];
-    [matches addObject:match];
+    NSInteger i = [matches count];
+    while (i-- > 0) {
+        PDFSelection *prevResult = [matches objectAtIndex:i];
+        if (SKCompareRects([match boundsForPage:page], [prevResult 
boundsForPage:page]) != NSOrderedAscending)
+            break;
+    }
+    [matches insertObject:match atIndex:i + 1];
     [self didChangeValueForKey:SKGroupedSearchResultCountKey];
 }
 

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2012-02-13 17:01:51 UTC (rev 7642)
+++ trunk/SKMainWindowController.m      2012-02-13 22:14:53 UTC (rev 7643)
@@ -1870,9 +1870,17 @@
         if ([string length] > l && [[NSCharacterSet letterCharacterSet] 
characterIsMember:[string characterAtIndex:0]])
             return;
     }
-    [searchResults addObject:instance];
     
     PDFPage *page = [instance safeFirstPage];
+    NSInteger i = [searchResults count];
+    while (i-- > 0) {
+        PDFSelection *prevResult = [searchResults objectAtIndex:i];
+        PDFPage *prevPage = [prevResult safeFirstPage];
+        if ([page isEqual:prevPage] == NO || SKCompareRects([instance 
boundsForPage:page], [prevResult boundsForPage:prevPage]) != NSOrderedAscending)
+            break;
+    }
+    [searchResults insertObject:instance atIndex:i + 1];
+    
     SKGroupedSearchResult *result = [groupedSearchResults lastObject];
     NSUInteger maxCount = [result maxCount];
     if ([[result page] isEqual:page] == NO) {

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


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to