From 5437f8a76e1654d5f67d5d102497a43799d9cc69 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sat, 1 Apr 2023 11:44:12 +0200 Subject: [PATCH 1/7] Added PageUp and PageDown KeyGestures --- .../Input/Platform/PlatformHotkeyConfiguration.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs index b87ca5eded..1bd54e37ea 100644 --- a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs +++ b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs @@ -85,6 +85,14 @@ namespace Avalonia.Input.Platform { new KeyGesture(Key.Left, KeyModifiers.Alt) }; + PageUp = new List + { + new KeyGesture(Key.PageUp) + }; + PageDown = new List + { + new KeyGesture(Key.PageDown) + }; } public KeyModifiers CommandModifiers { get; set; } @@ -106,5 +114,7 @@ namespace Avalonia.Input.Platform public List MoveCursorToTheEndOfDocumentWithSelection { get; set; } public List OpenContextMenu { get; set; } public List Back { get; set; } + public List PageUp { get; set; } + public List PageDown { get; set; } } } From e635d900ff80ee2bcc81eabd9dcbad83e88a87b8 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sun, 2 Apr 2023 14:36:44 +0200 Subject: [PATCH 2/7] Added PageRight and PageLeft Keygestures in PlatformHotkeyConfiguration --- .../Input/Platform/PlatformHotkeyConfiguration.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs index 1bd54e37ea..23950c2a71 100644 --- a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs +++ b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs @@ -85,6 +85,14 @@ namespace Avalonia.Input.Platform { new KeyGesture(Key.Left, KeyModifiers.Alt) }; + PageLeft = new List + { + new KeyGesture(Key.PageUp, KeyModifiers.Shift) + }; + PageRight = new List + { + new KeyGesture(Key.PageDown, KeyModifiers.Shift) + }; PageUp = new List { new KeyGesture(Key.PageUp) @@ -116,5 +124,7 @@ namespace Avalonia.Input.Platform public List Back { get; set; } public List PageUp { get; set; } public List PageDown { get; set; } + public List PageRight { get; set; } + public List PageLeft { get; set; } } } From 92ba4bc19c8fb36f574f74ba5067d619df045188 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sun, 2 Apr 2023 14:39:56 +0200 Subject: [PATCH 3/7] Added PageLeft, PageRight, PageUp, PageDown handling in TextBox Added cases in OnKeyDown method and added FetchChildScrollViewer method to fetch the child ScrollViewer in the VisualChildren. --- src/Avalonia.Controls/TextBox.cs | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 9bb68ba419..9c4be3a907 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/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 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; + } + /// /// Select all text in the TextBox /// From ca66c4d00db4d1b1ed2fc9c0c466626449978ed6 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sat, 1 Apr 2023 11:44:12 +0200 Subject: [PATCH 4/7] Added PageUp and PageDown KeyGestures --- .../Input/Platform/PlatformHotkeyConfiguration.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs index b87ca5eded..1bd54e37ea 100644 --- a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs +++ b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs @@ -85,6 +85,14 @@ namespace Avalonia.Input.Platform { new KeyGesture(Key.Left, KeyModifiers.Alt) }; + PageUp = new List + { + new KeyGesture(Key.PageUp) + }; + PageDown = new List + { + new KeyGesture(Key.PageDown) + }; } public KeyModifiers CommandModifiers { get; set; } @@ -106,5 +114,7 @@ namespace Avalonia.Input.Platform public List MoveCursorToTheEndOfDocumentWithSelection { get; set; } public List OpenContextMenu { get; set; } public List Back { get; set; } + public List PageUp { get; set; } + public List PageDown { get; set; } } } From 01cbf9790355e5ec909006b31811131b0ae086c5 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sun, 2 Apr 2023 14:36:44 +0200 Subject: [PATCH 5/7] Added PageRight and PageLeft Keygestures in PlatformHotkeyConfiguration --- .../Input/Platform/PlatformHotkeyConfiguration.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs index 1bd54e37ea..23950c2a71 100644 --- a/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs +++ b/src/Avalonia.Base/Input/Platform/PlatformHotkeyConfiguration.cs @@ -85,6 +85,14 @@ namespace Avalonia.Input.Platform { new KeyGesture(Key.Left, KeyModifiers.Alt) }; + PageLeft = new List + { + new KeyGesture(Key.PageUp, KeyModifiers.Shift) + }; + PageRight = new List + { + new KeyGesture(Key.PageDown, KeyModifiers.Shift) + }; PageUp = new List { new KeyGesture(Key.PageUp) @@ -116,5 +124,7 @@ namespace Avalonia.Input.Platform public List Back { get; set; } public List PageUp { get; set; } public List PageDown { get; set; } + public List PageRight { get; set; } + public List PageLeft { get; set; } } } From d25b9a4f88ed28267e28e5dc4d0531563a320566 Mon Sep 17 00:00:00 2001 From: nicola36631 Date: Sun, 2 Apr 2023 14:39:56 +0200 Subject: [PATCH 6/7] Added PageLeft, PageRight, PageUp, PageDown handling in TextBox Added cases in OnKeyDown method and added FetchChildScrollViewer method to fetch the child ScrollViewer in the VisualChildren. --- src/Avalonia.Controls/TextBox.cs | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 9bb68ba419..9c4be3a907 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/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 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; + } + /// /// Select all text in the TextBox /// From f4f3670c384d312e4d31161e637aff3f1ddf2f05 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Thu, 1 Jun 2023 07:32:21 +0200 Subject: [PATCH 7/7] Remove redundant using --- src/Avalonia.Controls/TextBox.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 873febd421..3016dc8239 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -17,7 +17,6 @@ using Avalonia.Controls.Metadata; using Avalonia.Media.TextFormatting; using Avalonia.Automation.Peers; using Avalonia.Threading; -using Avalonia.Collections; namespace Avalonia.Controls {