Browse Source
Merge pull request #3753 from FoggyFinder/issue3294
[ Skia ] Draw caret on center in case of empty TextBox
castxml-0.2
Benedikt Stebner
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
6 additions and
14 deletions
-
src/Skia/Avalonia.Skia/FormattedTextImpl.cs
|
|
|
@ -140,25 +140,17 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
public Rect HitTestTextPosition(int index) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(Text)) |
|
|
|
{ |
|
|
|
var alignmentOffset = TransformX(0, 0, _paint.TextAlign); |
|
|
|
return new Rect(alignmentOffset, 0, 0, _lineHeight); |
|
|
|
} |
|
|
|
var rects = GetRects(); |
|
|
|
|
|
|
|
if (index < 0 || index >= rects.Count) |
|
|
|
if (index >= Text.Length || index < 0) |
|
|
|
{ |
|
|
|
var r = rects.LastOrDefault(); |
|
|
|
return new Rect(r.X + r.Width, r.Y, 0, _lineHeight); |
|
|
|
} |
|
|
|
|
|
|
|
if (rects.Count == 0) |
|
|
|
{ |
|
|
|
return new Rect(0, 0, 1, _lineHeight); |
|
|
|
} |
|
|
|
|
|
|
|
if (index == rects.Count) |
|
|
|
{ |
|
|
|
var lr = rects[rects.Count - 1]; |
|
|
|
return new Rect(new Point(lr.X + lr.Width, lr.Y), rects[index - 1].Size); |
|
|
|
} |
|
|
|
|
|
|
|
return rects[index]; |
|
|
|
} |
|
|
|
|
|
|
|
|