aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextView.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-08-21 23:49:48 +0000
committerrowanbeentje <rowan@beent.je>2012-08-21 23:49:48 +0000
commit9ea88c6caefec56a0823ffe4a44a44204b0a51d2 (patch)
treec2e651dff95a85761fbd6d67951c26a62867b2c8 /Source/SPTextView.m
parenta98a327e0e5d16df778920c1108df69f48ccd8c9 (diff)
downloadsequelpro-9ea88c6caefec56a0823ffe4a44a44204b0a51d2.tar.gz
sequelpro-9ea88c6caefec56a0823ffe4a44a44204b0a51d2.tar.bz2
sequelpro-9ea88c6caefec56a0823ffe4a44a44204b0a51d2.zip
- Fix position of the autocomplete popup when the popup is just before a linebreak
- Tweak autocomplete poup to show the text positioned underneath the target word - Consolidate code
Diffstat (limited to 'Source/SPTextView.m')
-rw-r--r--Source/SPTextView.m54
1 files changed, 29 insertions, 25 deletions
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 44ee35d1..a9831b55 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -98,6 +98,7 @@ YY_BUFFER_STATE yy_scan_string (const char *);
NSInteger _alphabeticSort(id string1, id string2, void *reverse);
- (void)_setTextSelectionColor:(NSColor *)newSelectionColor onBackgroundColor:(NSColor *)aBackgroundColor;
+- (void)_positionCompletionPopup:(SPNarrowDownCompletion *)aPopup relativeToTextAtLocation:(NSUInteger)aLocation;
@end
@@ -914,17 +915,10 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS
completionParseRangeLocation = parseRange.location;
- //Get the NSPoint of the first character of the current word
- NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(completionRange.location,1) actualCharacterRange:NULL];
- NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[self textContainer]];
- boundingRect = [self convertRect:boundingRect toView:nil];
- NSPoint pos = [[self window] convertBaseToScreen:NSMakePoint(boundingRect.origin.x + boundingRect.size.width,boundingRect.origin.y + boundingRect.size.height)];
- pos.y -= [[self font] pointSize]*1.25f;
- [completionPopup setCaretPos:pos];
+ [self _positionCompletionPopup:completionPopup relativeToTextAtLocation:completionRange.location];
[completionPopup orderFront:self];
[completionPopup insertAutocompletePlaceholder];
-
}
@@ -1549,16 +1543,9 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS
alias:nil
withDBStructureRetriever:nil];
- //Get the NSPoint of the first character of the current word
- NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(aRange.location,1) actualCharacterRange:NULL];
- NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[self textContainer]];
- boundingRect = [self convertRect: boundingRect toView: NULL];
- NSPoint pos = [[self window] convertBaseToScreen: NSMakePoint(boundingRect.origin.x + boundingRect.size.width,boundingRect.origin.y + boundingRect.size.height)];
- // Adjust list location to be under the current word or insertion point
- pos.y -= [[self font] pointSize]*1.25f;
- [completionPopup setCaretPos:pos];
- [completionPopup orderFront:self];
+ [self _positionCompletionPopup:completionPopup relativeToTextAtLocation:aRange.location];
+ [completionPopup orderFront:self];
}
/**
@@ -1706,14 +1693,8 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS
alias:nil
withDBStructureRetriever:nil];
- //Get the NSPoint of the first character of the current word
- NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(r2.location,1) actualCharacterRange:NULL];
- NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[self textContainer]];
- boundingRect = [self convertRect: boundingRect toView: NULL];
- NSPoint pos = [[self window] convertBaseToScreen: NSMakePoint(boundingRect.origin.x + boundingRect.size.width,boundingRect.origin.y + boundingRect.size.height)];
- // Adjust list location to be under the current word or insertion point
- pos.y -= [[self font] pointSize]*1.25f;
- [completionPopup setCaretPos:pos];
+ [self _positionCompletionPopup:completionPopup relativeToTextAtLocation:r2.location];
+
[completionPopup orderFront:self];
}
}
@@ -3752,5 +3733,28 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:newSelectionColor, NSBackgroundColorAttributeName, nil]];
}
+/**
+ * Take a supplied autocompletion popup, and position it to the correct position
+ * for the text at the supplied text range location.
+ */
+- (void)_positionCompletionPopup:(SPNarrowDownCompletion *)aPopup relativeToTextAtLocation:(NSUInteger)aLocation
+{
+
+ // Get the range of glyphs generated from the character at the supplied location
+ NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(aLocation, 1) actualCharacterRange:NULL];
+
+ // Convert to a bounding rectangle in the window base coordinate system
+ NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[self textContainer]];
+ boundingRect = [self convertRect:boundingRect toView:nil];
+
+ // Convert the window position to a screen position
+ NSPoint screenPosition = [[self window] convertBaseToScreen:NSMakePoint(boundingRect.origin.x, boundingRect.origin.y)];
+
+ // Adjust the popup x location to compensate for horizontal padding and icon
+ screenPosition.x -= 26;
+
+ [aPopup setCaretPos:screenPosition];
+}
+
@end