aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/NoodleLineNumberView.h6
-rw-r--r--Source/NoodleLineNumberView.m71
2 files changed, 42 insertions, 35 deletions
diff --git a/Source/NoodleLineNumberView.h b/Source/NoodleLineNumberView.h
index 1d600720..7b1d2a5a 100644
--- a/Source/NoodleLineNumberView.h
+++ b/Source/NoodleLineNumberView.h
@@ -48,11 +48,17 @@
CGFloat maxWidthOfGlyph6;
CGFloat maxWidthOfGlyph7;
CGFloat maxWidthOfGlyph8;
+ CGFloat currentRuleThickness;
NSDictionary *textAttributes;
// Add support for selection by clicking/dragging
NSUInteger dragSelectionStartLine;
+ SEL lineNumberForCharacterIndexSel;
+ IMP lineNumberForCharacterIndexIMP;
+ SEL lineRangeForRangeSel;
+ SEL addObjectSel;
+ IMP addObjectIMP;
}
@property(retain) NSColor *alternateTextColor;
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m
index ebca542d..9fb57456 100644
--- a/Source/NoodleLineNumberView.m
+++ b/Source/NoodleLineNumberView.m
@@ -50,6 +50,8 @@
typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
+// Cache loop methods for speed
+
#pragma mark -
@interface NoodleLineNumberView (Private)
@@ -80,6 +82,15 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
nil] retain];
maxWidthOfGlyph = [[NSString stringWithString:@"8"] sizeWithAttributes:textAttributes].width;
[self updateGutterThicknessConstants];
+ currentRuleThickness = 0.0f;
+
+ // Cache loop methods for speed
+ lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
+ lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
+ lineRangeForRangeSel = @selector(lineRangeForRange:);
+ addObjectSel = @selector(addObject:);
+
+
}
return self;
@@ -218,10 +229,6 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
// It doesn't show up in the glyphs so would not be accounted for.
range.length++;
- // Cache loop methods for speed
- SEL lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
- IMP lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
-
for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
{
@@ -268,29 +275,6 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
return left;
}
-- (CGFloat)requiredThickness
-{
- NSUInteger lineCount = [[self lineIndices] count];
- if(lineCount < 10)
- return maxWidthOfGlyph1;
- else if(lineCount < 100)
- return maxWidthOfGlyph2;
- else if(lineCount < 1000)
- return maxWidthOfGlyph3;
- else if(lineCount < 10000)
- return maxWidthOfGlyph4;
- else if(lineCount < 100000)
- return maxWidthOfGlyph5;
- else if(lineCount < 1000000)
- return maxWidthOfGlyph6;
- else if(lineCount < 10000000)
- return maxWidthOfGlyph7;
- else if(lineCount < 100000000)
- return maxWidthOfGlyph8;
- else
- return 100;
-}
-
- (void)drawHashMarksAndLabelsInRect:(NSRect)aRect
{
id view;
@@ -345,9 +329,6 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
CGFloat yinsetMinY = yinset - NSMinY(visibleRect);
CGFloat rectHeight;
- // Cache loop methods for speed
- SEL lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
- IMP lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
{
@@ -539,10 +520,8 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
index = 0;
// Cache loop methods for speed
- SEL lineRangeForRangeSel = @selector(lineRangeForRange:);
- SEL addObjectSel = @selector(addObject:);
RangeOfLineIMP rangeOfLineIMP = (RangeOfLineIMP)[textString methodForSelector:lineRangeForRangeSel];
- IMP addObjectIMP = [lineIndices methodForSelector:addObjectSel];
+ addObjectIMP = [lineIndices methodForSelector:addObjectSel];
do
{
@@ -556,9 +535,31 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
if (contentEnd < lineEnd)
(void*)(*addObjectIMP)(lineIndices, addObjectSel, [NSNumber numberWithUnsignedInteger:index]);
- newThickness = [self requiredThickness];
- if (fabs([self ruleThickness] - newThickness) > 1)
+ NSUInteger lineCount = [lineIndices count];
+ if(lineCount < 10)
+ newThickness = maxWidthOfGlyph1;
+ else if(lineCount < 100)
+ newThickness = maxWidthOfGlyph2;
+ else if(lineCount < 1000)
+ newThickness = maxWidthOfGlyph3;
+ else if(lineCount < 10000)
+ newThickness = maxWidthOfGlyph4;
+ else if(lineCount < 100000)
+ newThickness = maxWidthOfGlyph5;
+ else if(lineCount < 1000000)
+ newThickness = maxWidthOfGlyph6;
+ else if(lineCount < 10000000)
+ newThickness = maxWidthOfGlyph7;
+ else if(lineCount < 100000000)
+ newThickness = maxWidthOfGlyph8;
+ else
+ newThickness = 100;
+
+ if (fabs(currentRuleThickness - newThickness) > 1)
{
+
+ currentRuleThickness = newThickness;
+
// Not a good idea to resize the view during calculations (which can happen during
// display). Do a delayed perform (using NSInvocation since arg is a float).
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(setRuleThickness:)]];