From 454dc28a80e2bb4db0e136852969ae83b13dd082 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 10 Mar 2008 16:39:38 -0400 Subject: [PATCH] The mouse down handler almost works, but our math is still off * Source/BSLineNumberView.m: ([BSLineNumberView mouseDown:]) --- Source/BSLineNumberView.m | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Source/BSLineNumberView.m b/Source/BSLineNumberView.m index 003a6f6..d7c9f57 100644 --- a/Source/BSLineNumberView.m +++ b/Source/BSLineNumberView.m @@ -87,22 +87,26 @@ */ - (void)mouseDown:(NSEvent *)event { - NSLog(@"mouse down!"); - NSRange visible = [[[sourceView textView] layoutManager] glyphRangeForBoundingRect:[[sourceView scrollView] documentVisibleRect] inTextContainer:[[sourceView textView] textContainer]]; + // simplify our code a bit + NSScrollView *scrollView = [sourceView scrollView]; + NSTextView *textView = [sourceView textView]; + + NSPoint clickLoc = [self convertPoint:[event locationInWindow] fromView:nil]; + + // calculate the relative difference between height of the line number view and the document view + float adjust = (int)([scrollView documentVisibleRect].size.height + [scrollView documentVisibleRect].origin.y) % (int)[self bounds].size.height; + adjust += [[textView layoutManager] lineFragmentRectForGlyphAtIndex:0 effectiveRange:NULL].size.height; + clickLoc.y += adjust; // apply that to the click location to make it seem like we're clicking in an unclipped region + unsigned line = 1; unsigned i = 0; - NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil]; - float adjust = (int)([[sourceView scrollView] documentVisibleRect].size.height + [[sourceView scrollView] documentVisibleRect].origin.y) % (int)[self bounds].size.height; - p.y += adjust; - while (i < [[[sourceView textView] layoutManager] numberOfGlyphs]) + while (i < [[textView layoutManager] numberOfGlyphs]) { NSRange fragRange; - NSRect fragRect = [[[sourceView textView] layoutManager] lineFragmentRectForGlyphAtIndex:i effectiveRange:&fragRange]; + NSRect fragRect = [[textView layoutManager] lineFragmentRectForGlyphAtIndex:i effectiveRange:&fragRange]; fragRect.size.width = [self bounds].size.width; - int hLV = [self bounds].size.height; - int hVR = [[sourceView scrollView] documentVisibleRect].size.height + [[sourceView scrollView] documentVisibleRect].origin.y; - fragRect.origin.y += hVR % hLV; - if (i >= visible.location && NSPointInRect(p, fragRect)) + //fragRect.origin.y += adjust; + if (NSPointInRect(clickLoc, fragRect)) { NSLog(@"clicked in %i", line); break; -- 2.22.5