mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-09 10:20:59 +00:00
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:
1 parent
d5f38fe2f2
commit
78e29d2bbf
2 files changed
+44
No files matched your search
@@ -129,6 +129,41 @@ var DOMFixedWidthSpanElement = nil,
|
||||
DOMMetricsDivElement.appendChild(DOMMetricsImgElement);
|
||||
}
|
||||
|
||||
+ (int)charPositionOfString:(CPString)aString withFont:(CPFont)aFont forPoint:(CGPoint)aPoint
|
||||
{
|
||||
if (!aString)
|
||||
return 0;
|
||||
|
||||
var position = 0,
|
||||
stringLength = aString.length,
|
||||
currentString = "";
|
||||
|
||||
for (var i = 0; i < stringLength; i++)
|
||||
{
|
||||
var char = aString[i];
|
||||
|
||||
currentString += char;
|
||||
|
||||
var sizeOfString = [self sizeOfString:currentString withFont:aFont forWidth:nil].width;
|
||||
|
||||
if (sizeOfString < aPoint.x)
|
||||
{
|
||||
position++;
|
||||
}
|
||||
else
|
||||
{
|
||||
var sizeLastChar = [self sizeOfString:char withFont:aFont forWidth:nil].width;
|
||||
|
||||
if (sizeOfString - sizeLastChar / 2 < aPoint.x)
|
||||
position++;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
+ (CGSize)sizeOfString:(CPString)aString withFont:(CPFont)aFont forWidth:(float)aWidth
|
||||
{
|
||||
if (!DOMFixedWidthSpanElement)
|
||||
|
||||
Reference in new issue
Block a user