Browse Source

Merge pull request #10882 from nicola36631/milestone/11.0/feature/textbox-PgUp-PgDn

[TextBox] Add page keyboard navigation
pull/11605/head
Max Katz 3 years ago
committed by GitHub
parent
commit
f52fa669f3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs
  2. 50
      src/Avalonia.Controls/TextBox.cs

20
src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs

@ -89,6 +89,22 @@ namespace Avalonia.Input.Platform
{
new KeyGesture(Key.Left, KeyModifiers.Alt)
};
PageLeft = new List<KeyGesture>
{
new KeyGesture(Key.PageUp, KeyModifiers.Shift)
};
PageRight = new List<KeyGesture>
{
new KeyGesture(Key.PageDown, KeyModifiers.Shift)
};
PageUp = new List<KeyGesture>
{
new KeyGesture(Key.PageUp)
};
PageDown = new List<KeyGesture>
{
new KeyGesture(Key.PageDown)
};
}
public KeyModifiers CommandModifiers { get; set; }
@ -110,5 +126,9 @@ namespace Avalonia.Input.Platform
public List<KeyGesture> MoveCursorToTheEndOfDocumentWithSelection { get; set; }
public List<KeyGesture> OpenContextMenu { get; set; }
public List<KeyGesture> Back { get; set; }
public List<KeyGesture> PageUp { get; set; }
public List<KeyGesture> PageDown { get; set; }
public List<KeyGesture> PageRight { get; set; }
public List<KeyGesture> PageLeft { get; set; }
}
}

50
src/Avalonia.Controls/TextBox.cs

@ -15,7 +15,6 @@ using Avalonia.Layout;
using Avalonia.Utilities;
using Avalonia.Controls.Metadata;
using Avalonia.Media.TextFormatting;
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Automation.Peers;
using Avalonia.Threading;
@ -1214,6 +1213,34 @@ namespace Avalonia.Controls
selection = true;
handled = true;
}
else if (Match(keymap.PageLeft))
{
MovePageLeft();
movement = true;
selection = false;
handled = true;
}
else if (Match(keymap.PageRight))
{
MovePageRight();
movement = true;
selection = false;
handled = true;
}
else if (Match(keymap.PageUp))
{
MovePageUp();
movement = true;
selection = false;
handled = true;
}
else if (Match(keymap.PageDown))
{
MovePageDown();
movement = true;
selection = false;
handled = true;
}
else
{
bool hasWholeWordModifiers = modifiers.HasAllFlags(keymap.WholeWordTextActionModifiers);
@ -1404,8 +1431,6 @@ namespace Avalonia.Controls
{
var point = e.GetPosition(_presenter);
var oldIndex = CaretIndex;
_presenter.MoveCaretToPoint(point);
var caretIndex = _presenter.CaretIndex;
@ -1738,6 +1763,25 @@ namespace Avalonia.Controls
}
}
private void MovePageRight()
{
_scrollViewer?.PageRight();
}
private void MovePageLeft()
{
_scrollViewer?.PageLeft();
}
private void MovePageUp()
{
_scrollViewer?.PageUp();
}
private void MovePageDown()
{
_scrollViewer?.PageDown();
}
/// <summary>
/// Select all text in the TextBox
/// </summary>

Loading…
Cancel
Save