Revision: 14942
          http://sourceforge.net/p/skim-app/code/14942
Author:   hofman
Date:     2025-03-05 10:10:55 +0000 (Wed, 05 Mar 2025)
Log Message:
-----------
get index from index specifier directly, common case

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

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2025-03-04 17:52:38 UTC (rev 14941)
+++ trunk/PDFSelection_SKExtensions.m   2025-03-05 10:10:55 UTC (rev 14942)
@@ -322,7 +322,17 @@
                     NSScriptObjectSpecifier *endSpec = [(NSRangeSpecifier 
*)specifier endSpecifier];
                     
                     if (startSpec || endSpec) {
-                        if (startSpec) {
+                        if ([startSpec isKindOfClass:[NSIndexSpecifier 
class]]) {
+                            startIndex = [(NSIndexSpecifier *)startSpec index];
+                            if (startIndex < 0) {
+                                if ([key isEqualToString:CHARACTERS_KEY]) {
+                                    startIndex += [textStorage length];
+                                } else {
+                                    subTextStorages = [textStorage 
valueForKey:key];
+                                    startIndex += [subTextStorages count];
+                                }
+                            }
+                        } else if (startSpec) {
                             count = -2;
                             indices = [startSpec 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];
                             startIndex = count > 0 ? indices[0] : -1;
@@ -329,7 +339,17 @@
                         } else {
                             startIndex = 0;
                         }
-                        if (endSpec) {
+                        if ([endSpec isKindOfClass:[NSIndexSpecifier class]]) {
+                            endIndex = [(NSIndexSpecifier *)endSpec index];
+                            if (endIndex < 0) {
+                                if ([key isEqualToString:CHARACTERS_KEY]) {
+                                    endIndex += [textStorage length];
+                                } else {
+                                    subTextStorages = [textStorage 
valueForKey:key];
+                                    endIndex += [subTextStorages count];
+                                }
+                            }
+                        } else if (endSpec) {
                             count = -2;
                             indices = [endSpec 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];
                             endIndex = count > 0 ? indices[count - 1] : -1;
@@ -344,6 +364,18 @@
                             [tmpRanges addPointer:&range];
                         }
                     }
+                } else if ([specifier isKindOfClass:[NSIndexSpecifier class]]) 
{
+                    NSInteger idx = [(NSIndexSpecifier *)specifier index];
+                    if (idx < 0) {
+                        if ([key isEqualToString:CHARACTERS_KEY]) {
+                            idx += [textStorage length];
+                        } else {
+                            subTextStorages = [textStorage valueForKey:key];
+                            idx += [subTextStorages count];
+                        }
+                    }
+                    NSRange range = NSMakeRange(idx, 1);
+                    [tmpRanges addPointer:&range];
                 } else {
                     // this handles other objectSpecifiers (index, middel, 
random, relative, whose). It can contain several ranges, e.g. for aan 
NSWhoseSpecifier
                     indices = [specifier 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to