Browse Source

Merge branch 'milestone/11.0/feature/textbox-PgUp-PgDn' of https://github.com/nicola36631/Avalonia into feature/textBoxPageNavigation

pull/10882/head
Benedikt Stebner 3 years ago
parent
commit
8c22c32c39
  1. 20
      src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs
  2. 92
      src/Avalonia.Controls/TextBox.cs

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

@ -85,6 +85,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; }
@ -106,5 +122,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; }
}
}

92
src/Avalonia.Controls/TextBox.cs

@ -19,6 +19,7 @@ using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Automation.Peers;
using Avalonia.Threading;
using Avalonia.Platform;
using Avalonia.Collections;
namespace Avalonia.Controls
{
@ -1240,6 +1241,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);
@ -1755,6 +1784,69 @@ namespace Avalonia.Controls
}
}
private void MovePageRight()
{
ScrollViewer? childScrollviewer = FetchChildScrollViewer(10, 0, this.VisualChildren);
if (childScrollviewer == null)
{
return;
}
childScrollviewer.PageRight();
}
private void MovePageLeft()
{
ScrollViewer? childScrollviewer = FetchChildScrollViewer(10, 0, this.VisualChildren);
if (childScrollviewer == null)
{
return;
}
childScrollviewer.PageLeft();
}
private void MovePageUp()
{
ScrollViewer? childScrollviewer = FetchChildScrollViewer(10, 0, this.VisualChildren);
if (childScrollviewer == null)
{
return;
}
childScrollviewer.PageUp();
}
private void MovePageDown()
{
ScrollViewer? childScrollviewer = FetchChildScrollViewer(10, 0, this.VisualChildren);
if (childScrollviewer == null)
{
return;
}
childScrollviewer.PageDown();
}
private ScrollViewer? FetchChildScrollViewer(in int maxSearchDepth, int currentSearchDepth, IAvaloniaList<Visual> visualChildren)
{
foreach(Visual innerChild in visualChildren)
{
if(innerChild is ScrollViewer)
{
return (ScrollViewer?)innerChild;
}
else
{
if (currentSearchDepth < maxSearchDepth)
{
ScrollViewer? innerScrollViewer = FetchChildScrollViewer(maxSearchDepth, currentSearchDepth + 1, innerChild.VisualChildren);
if (innerScrollViewer != null)
{
return innerScrollViewer;
}
}
}
}
return null;
}
/// <summary>
/// Select all text in the TextBox
/// </summary>

Loading…
Cancel
Save