Browse Source

Merge pull request #2074 from Sorien/edit-box-selection

make sure pointer is always inside presenter
text-input
Steven Kirk 8 years ago
committed by GitHub
parent
commit
a3c0962887
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Controls/TextBox.cs
  2. 2
      src/Skia/Avalonia.Skia/FormattedTextImpl.cs

3
src/Avalonia.Controls/TextBox.cs

@ -14,6 +14,7 @@ using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.Data;
using Avalonia.Utilities;
namespace Avalonia.Controls
{
@ -655,6 +656,8 @@ namespace Avalonia.Controls
if (_presenter != null && e.Device.Captured == _presenter)
{
var point = e.GetPosition(_presenter);
point = new Point(MathUtilities.Clamp(point.X, 0, _presenter.Bounds.Width - 1), MathUtilities.Clamp(point.Y, 0, _presenter.Bounds.Height - 1));
CaretIndex = SelectionEnd = _presenter.GetCaretIndex(point);
}
}

2
src/Skia/Avalonia.Skia/FormattedTextImpl.cs

@ -121,7 +121,7 @@ namespace Avalonia.Skia
int offset = 0;
if (point.X >= (rects[line.Start].X + line.Width) / 2 && line.Length > 0)
if (point.X >= (rects[line.Start].X + line.Width) && line.Length > 0)
{
offset = line.TextLength > line.Length ?
line.Length : (line.Length - 1);

Loading…
Cancel
Save