diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/NoodleLineNumberView.m | 141 | ||||
-rw-r--r-- | Source/SPBundleCommandTextView.m | 20 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 2 |
3 files changed, 80 insertions, 83 deletions
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m index 0bb9b25e..9e0d284a 100644 --- a/Source/NoodleLineNumberView.m +++ b/Source/NoodleLineNumberView.m @@ -353,7 +353,7 @@ - (void)drawHashMarksAndLabelsInRect:(NSRect)aRect { - id view; + id view; NSRect bounds; bounds = [self bounds]; @@ -362,87 +362,88 @@ { [backgroundColor set]; NSRectFill(bounds); - + [[NSColor colorWithCalibratedWhite:0.58 alpha:1.0] set]; - [NSBezierPath strokeLineFromPoint:NSMakePoint(NSMaxX(bounds) - 0/5, NSMinY(bounds)) toPoint:NSMakePoint(NSMaxX(bounds) - 0.5, NSMaxY(bounds))]; + [NSBezierPath strokeLineFromPoint:NSMakePoint(NSMaxX(bounds) - 0.5, NSMinY(bounds)) toPoint:NSMakePoint(NSMaxX(bounds) - 0.5, NSMaxY(bounds))]; } - - view = [self clientView]; - - if ([view isKindOfClass:[NSTextView class]]) - { - NSLayoutManager *layoutManager; - NSTextContainer *container; - NSRect visibleRect; - NSRange range, glyphRange, nullRange; - NSString *text, *labelText; - NSUInteger rectCount, index, line, count; - NSRectArray rects; - CGFloat ypos, yinset; - NSDictionary *textAttributes, *currentTextAttributes; - NSSize stringSize; + + view = [self clientView]; + + if ([view isKindOfClass:[NSTextView class]]) + { + NSLayoutManager *layoutManager; + NSTextContainer *container; + NSRect visibleRect; + NSRange range, glyphRange, nullRange; + NSString *text, *labelText; + NSUInteger rectCount, index, line, count; + NSRectArray rects; + CGFloat ypos, yinset; + NSDictionary *textAttributes; + NSSize stringSize; NSMutableArray *lines; - layoutManager = [view layoutManager]; - container = [view textContainer]; - text = [view string]; - nullRange = NSMakeRange(NSNotFound, 0); - + layoutManager = [view layoutManager]; + container = [view textContainer]; + text = [view string]; + nullRange = NSMakeRange(NSNotFound, 0); + yinset = [view textContainerInset].height; - visibleRect = [[[self scrollView] contentView] bounds]; + visibleRect = [[[self scrollView] contentView] bounds]; + + textAttributes = [self textAttributes]; - textAttributes = [self textAttributes]; - lines = [self lineIndices]; - // Find the characters that are currently visible - glyphRange = [layoutManager glyphRangeForBoundingRect:visibleRect inTextContainer:container]; - range = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL]; - - // Fudge the range a tad in case there is an extra new line at end. - // It doesn't show up in the glyphs so would not be accounted for. - range.length++; - - count = [lines count]; - - for (line = [self lineNumberForCharacterIndex:range.location inText:text]; line < count; line++) - { - index = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue]; - - if (NSLocationInRange(index, range)) - { - rects = [layoutManager rectArrayForCharacterRange:NSMakeRange(index, 0) - withinSelectedCharacterRange:nullRange - inTextContainer:container - rectCount:&rectCount]; - - if (rectCount > 0) - { - // Note that the ruler view is only as tall as the visible - // portion. Need to compensate for the clipview's coordinates. - ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect); - - // Line numbers are internally stored starting at 0 - labelText = [NSString stringWithFormat:@"%lu", (unsigned long)(line + 1)]; - - stringSize = [labelText sizeWithAttributes:textAttributes]; - - currentTextAttributes = textAttributes; - - // Draw string flush right, centered vertically within the line - [labelText drawInRect: - NSMakeRect(NSWidth(bounds) - stringSize.width - RULER_MARGIN, - ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0, - NSWidth(bounds) - RULER_MARGIN * 2.0, NSHeight(rects[0])) - withAttributes:currentTextAttributes]; - } - } + // Find the characters that are currently visible + glyphRange = [layoutManager glyphRangeForBoundingRect:visibleRect inTextContainer:container]; + range = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL]; + + // Fudge the range a tad in case there is an extra new line at end. + // It doesn't show up in the glyphs so would not be accounted for. + range.length++; + + count = [lines count]; + + CGFloat boundsRULERMargin2 = NSWidth(bounds) - RULER_MARGIN * 2.0; + CGFloat boundsWidthRULER = NSWidth(bounds) - RULER_MARGIN; + CGFloat yinsetMinY = yinset - NSMinY(visibleRect); + + for (line = [self lineNumberForCharacterIndex:range.location inText:text]; line < count; line++) + { + index = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue]; + + if (NSLocationInRange(index, range)) + { + rects = [layoutManager rectArrayForCharacterRange:NSMakeRange(index, 0) + withinSelectedCharacterRange:nullRange + inTextContainer:container + rectCount:&rectCount]; + + if (rectCount > 0) + { + // Note that the ruler view is only as tall as the visible + // portion. Need to compensate for the clipview's coordinates. + + // Line numbers are internally stored starting at 0 + labelText = [NSString stringWithFormat:@"%lu", (NSUInteger)(line + 1)]; + + stringSize = [labelText sizeWithAttributes:textAttributes]; + + // Draw string flush right, centered vertically within the line + [labelText drawInRect: + NSMakeRect(boundsWidthRULER - stringSize.width, + yinsetMinY + NSMinY(rects[0]) + ((NSHeight(rects[0]) - stringSize.height) / 2.0), + boundsRULERMargin2, NSHeight(rects[0])) + withAttributes:textAttributes]; + } + } if (index > NSMaxRange(range)) { break; } - } - } + } + } } - (void)mouseDown:(NSEvent *)theEvent diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index 8a5bf620..6411ccfd 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -29,25 +29,15 @@ @implementation SPBundleCommandTextView -- (id)init -{ - if(self = [super init]) - { - ; - } - return self; -} - - (void)dealloc { - - [[NSNotificationCenter defaultCenter] removeObserver:self]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; [prefs release]; [lineNumberView release]; } -- (void) awakeFromNib +- (void)awakeFromNib { prefs = [[NSUserDefaults standardUserDefaults] retain]; @@ -68,6 +58,12 @@ // Re-define tab stops for a better editing [self setTabStops]; + // add NSViewBoundsDidChangeNotification to scrollView + [[commandScrollView contentView] setPostsBoundsChangedNotifications:YES]; + + // disabled to get the current text range in textView safer + [[self layoutManager] setBackgroundLayoutEnabled:NO]; + } - (void)drawRect:(NSRect)rect diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 11defa20..3eeb46ce 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -534,7 +534,7 @@ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"]) ; + BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"] && [self respondsToSelector:@selector(currentQueryRange)]) ; if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; |