Browse Source

check we have a presenter before allowing navigation inside textbox.

pull/6213/head
Dan Walmsley 5 years ago
parent
commit
d0133ebb8c
  1. 45
      src/Avalonia.Controls/TextBox.cs

45
src/Avalonia.Controls/TextBox.cs

@ -1098,29 +1098,35 @@ namespace Avalonia.Controls
private bool MoveVertical(int count)
{
var formattedText = _presenter.FormattedText;
var lines = formattedText.GetLines().ToList();
var caretIndex = CaretIndex;
var lineIndex = GetLine(caretIndex, lines) + count;
if (lineIndex >= 0 && lineIndex < lines.Count)
{
var line = lines[lineIndex];
var rect = formattedText.HitTestTextPosition(caretIndex);
var y = count < 0 ? rect.Y : rect.Bottom;
var point = new Point(rect.X, y + (count * (line.Height / 2)));
var hit = formattedText.HitTestPoint(point);
CaretIndex = hit.TextPosition + (hit.IsTrailing ? 1 : 0);
return true;
}
else
if (_presenter != null)
{
return false;
var formattedText = _presenter.FormattedText;
var lines = formattedText.GetLines().ToList();
var caretIndex = CaretIndex;
var lineIndex = GetLine(caretIndex, lines) + count;
if (lineIndex >= 0 && lineIndex < lines.Count)
{
var line = lines[lineIndex];
var rect = formattedText.HitTestTextPosition(caretIndex);
var y = count < 0 ? rect.Y : rect.Bottom;
var point = new Point(rect.X, y + (count * (line.Height / 2)));
var hit = formattedText.HitTestPoint(point);
CaretIndex = hit.TextPosition + (hit.IsTrailing ? 1 : 0);
return true;
}
}
return false;
}
private void MoveHome(bool document)
{
if (_presenter == null)
{
return;
}
var text = Text ?? string.Empty;
var caretIndex = CaretIndex;
@ -1151,6 +1157,11 @@ namespace Avalonia.Controls
private void MoveEnd(bool document)
{
if (_presenter == null)
{
return;
}
var text = Text ?? string.Empty;
var caretIndex = CaretIndex;

Loading…
Cancel
Save