Fixed: position of cursor in a CPTextField was wrong when becoming firstResponder

Previously, when a CPTextField became firstResponder, the cursor was always set at the first position. Now it position it at the expected location.
This commit is contained in:
Alexandre Wilhelm
2015-10-31 12:31:49 -07:00
parent d5f38fe2f2
commit 78e29d2bbf
2 changed files with 44 additions and 0 deletions
+9
View File
@@ -684,7 +684,16 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// Select the text if the textfield became first responder through keyboard interaction
if (!_willBecomeFirstResponderByClick)
{
[self _selectText:self immediately:YES];
}
else
{
var point = CGPointMake([self convertPointFromBase:[[CPApp currentEvent] locationInWindow]].x - [self currentValueForThemeAttribute:@"content-inset"].left, 0),
position = [CPPlatformString charPositionOfString:[self stringValue] withFont:[self font] forPoint:point];
[self setSelectedRange:CPMakeRange(position, 0)];
}
_willBecomeFirstResponderByClick = NO;