Revision: 14929
          http://sourceforge.net/p/skim-app/code/14929
Author:   hofman
Date:     2025-03-01 18:10:23 +0000 (Sat, 01 Mar 2025)
Log Message:
-----------
macro for lazily loaded sub text storages

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

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2025-03-01 18:04:50 UTC (rev 14928)
+++ trunk/PDFSelection_SKExtensions.m   2025-03-01 18:10:23 UTC (rev 14929)
@@ -268,6 +268,8 @@
 #define RICH_TEXT_CLASSNAME @"rich text"
 #define CHARACTERS_KEY @"characters"
 
+#define SUB_TEXT_STORAGES (subTextStorages ?: (subTextStorages = [textStorage 
valueForKey:key]))
+
 static NSArray 
*characterRangesAndContainersForSpecifier(NSScriptObjectSpecifier *specifier, 
BOOL continuous, BOOL continuousContainers) {
     if ([specifier isKindOfClass:[NSScriptObjectSpecifier class]] == NO)
         return nil;
@@ -308,13 +310,10 @@
                 if ([specifier isKindOfClass:[NSPropertySpecifier class]]) {
                     // this should be the full range of characters, words, or 
paragraphs
                     NSRange range = NSMakeRange(0, 0);
-                    if ([key isEqualToString:@"character"]) {
+                    if ([key isEqualToString:@"character"])
                         range.length = [textStorage length];
-                    } else {
-                        if (subTextStorages == nil)
-                            subTextStorages = [textStorage valueForKey:key];
-                        range.length = [subTextStorages count];
-                    }
+                    else
+                        range.length = [SUB_TEXT_STORAGES count];
                     if (range.length)
                         [tmpRanges addPointer:&range];
                 } else if ([specifier isKindOfClass:[NSRangeSpecifier class]]) 
{
@@ -335,13 +334,10 @@
                             indices = [endSpec 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];
                             endIndex = count > 0 ? indices[count - 1] : -1;
                         } else {
-                            if ([key isEqualToString:@"character"]) {
+                            if ([key isEqualToString:@"character"])
                                 endIndex = [textStorage length] - 1;
-                            } else {
-                                if (subTextStorages == nil)
-                                    subTextStorages = [textStorage 
valueForKey:key];
-                                endIndex = [subTextStorages count] - 1;
-                            }
+                            else
+                                endIndex = [SUB_TEXT_STORAGES count] - 1;
                         }
                         if (startIndex >= 0 && endIndex >= 0) {
                             NSRange range = NSMakeRange(MIN(startIndex, 
endIndex), MAX(startIndex, endIndex) + 1 - MIN(startIndex, endIndex));
@@ -353,13 +349,10 @@
                     indices = [specifier 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];
                     NSRange range = NSMakeRange(0, 0);
                     if (count == -1) {
-                        if ([key isEqualToString:@"character"]) {
+                        if ([key isEqualToString:@"character"])
                             range.length = [textStorage length];
-                        } else {
-                            if (subTextStorages == nil)
-                                subTextStorages = [textStorage 
valueForKey:key];
-                            range.length = [subTextStorages count];
-                        }
+                        else
+                            range.length = [SUB_TEXT_STORAGES count];
                     } else if (count > 0) {
                         for (i = 0; i < count; i++) {
                             NSUInteger idx = indices[i];
@@ -397,9 +390,7 @@
                     }
                 } else {
                     // translate from subtext ranges to character ranges
-                    if (subTextStorages == nil)
-                        subTextStorages = [textStorage valueForKey:key];
-                    if ([subTextStorages count]) {
+                    if ([SUB_TEXT_STORAGES count]) {
                         NSString *string = nil;
                         NSArray *substrings = nil;
                         // The private subclass NSSubTextStorage has a -range 
method

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