Browse Source

Fixed TableView key handling

Tig 9 months ago
parent
commit
61be0615e0

+ 60 - 40
Terminal.Gui/View/View.Keyboard.cs

@@ -268,63 +268,84 @@ public partial class View // Keyboard APIs
             return false;
         }
 
-        // By default the KeyBindingScope is View
-
+        // If there's a Focused subview, give it a chance (this recurses down the hierarchy)
         if (Focused?.NewKeyDownEvent (key) == true)
         {
             return true;
         }
 
+        // Before (fire the cancellable event)
         if (RaiseKeyDown (key) || key.Handled)
         {
             return true;
         }
 
         // During (this is what can be cancelled)
-        InvokingKeyBindings?.Invoke (this, key);
 
-        if (key.Handled)
+        if (RaiseInvokingKeyBindings (key) || key.Handled)
         {
             return true;
         }
 
-        // TODO: NewKeyDownEvent returns bool. It should be bool? so state of InvokeCommand can be reflected up stack
-
-        bool? handled = OnInvokingKeyBindings (key, KeyBindingScope.HotKey | KeyBindingScope.Focused);
-
-        if (handled is { } && (bool)handled)
+        if (RaiseProcessKeyDown(key) || key.Handled)
         {
             return true;
         }
 
-        // TODO: The below is not right. OnXXX handlers are supposed to fire the events.
-        // TODO: But I've moved it outside of the v-function to test something.
-        // After (fire the cancellable event)
-        // fire event
-        ProcessKeyDown?.Invoke (this, key);
+        return key.Handled;
 
-        if (!key.Handled && OnProcessKeyDown (key))
+        bool RaiseKeyDown (Key key)
         {
-            return true;
-        }
+            // Before (fire the cancellable event)
+            if (OnKeyDown (key) || key.Handled)
+            {
+                return true;
+            }
 
-        return key.Handled;
-    }
+            // fire event
+            KeyDown?.Invoke (this, key);
 
-    private bool RaiseKeyDown (Key key)
-    {
-        // Before (fire the cancellable event)
-        if (OnKeyDown (key) || key.Handled)
+            return key.Handled;
+        }
+
+        bool RaiseInvokingKeyBindings (Key key)
         {
-            return true;
+            // BUGBUG: The proper pattern is for the v-method (OnInvokingKeyBindings) to be called first, then the event
+            InvokingKeyBindings?.Invoke (this, key);
+
+            if (key.Handled)
+            {
+                return true;
+            }
+
+            // TODO: NewKeyDownEvent returns bool. It should be bool? so state of InvokeCommand can be reflected up stack
+
+            bool? handled = OnInvokingKeyBindings (key, KeyBindingScope.HotKey | KeyBindingScope.Focused);
+
+            if (handled is { } && (bool)handled)
+            {
+                return true;
+            }
+
+            return false;
         }
 
-        // fire event
-        KeyDown?.Invoke (this, key);
+        bool RaiseProcessKeyDown (Key key)
+        {
+            // BUGBUG: The proper pattern is for the v-method (OnProcessKeyDown) to be called first, then the event
+            ProcessKeyDown?.Invoke (this, key);
 
-        return key.Handled;
+            if (!key.Handled && OnProcessKeyDown (key))
+            {
+                return true;
+            }
+
+            return false;
+        }
     }
 
+
+
     /// <summary>
     ///     Low-level API called when the user presses a key, allowing a view to pre-process the key down event. This is
     ///     called from <see cref="NewKeyDownEvent"/> before <see cref="OnInvokingKeyBindings"/>.
@@ -341,7 +362,7 @@ public partial class View // Keyboard APIs
     ///     </para>
     ///     <para>Fires the <see cref="KeyDown"/> event.</para>
     /// </remarks>
-    public virtual bool OnKeyDown (Key keyEvent)
+    protected virtual bool OnKeyDown (Key keyEvent)
     {
         return false;
     }
@@ -384,9 +405,8 @@ public partial class View // Keyboard APIs
     ///         KeyUp events.
     ///     </para>
     /// </remarks>
-    public virtual bool OnProcessKeyDown (Key keyEvent)
+    protected virtual bool OnProcessKeyDown (Key keyEvent)
     {
-        //ProcessKeyDown?.Invoke (this, keyEvent);
         return keyEvent.Handled;
     }
 
@@ -446,20 +466,20 @@ public partial class View // Keyboard APIs
         }
 
         return false;
-    }
 
-    private bool RaiseKeyUp (Key key)
-    {
-        // Before (fire the cancellable event)
-        if (OnKeyUp (key) || key.Handled)
+        bool RaiseKeyUp (Key key)
         {
-            return true;
-        }
+            // Before (fire the cancellable event)
+            if (OnKeyUp (key) || key.Handled)
+            {
+                return true;
+            }
 
-        // fire event
-        KeyUp?.Invoke (this, key);
+            // fire event
+            KeyUp?.Invoke (this, key);
 
-        return key.Handled;
+            return key.Handled;
+        }
     }
 
 

+ 1 - 1
Terminal.Gui/Views/DateField.cs

@@ -131,7 +131,7 @@ public class DateField : TextField
     public virtual void OnDateChanged (DateTimeEventArgs<DateTime> args) { DateChanged?.Invoke (this, args); }
 
     /// <inheritdoc/>
-    public override bool OnProcessKeyDown (Key a)
+    protected override bool OnProcessKeyDown (Key a)
     {
         // Ignore non-numeric characters.
         if (a >= Key.D0 && a <= Key.D9)

+ 1 - 1
Terminal.Gui/Views/FileDialog.cs

@@ -233,7 +233,7 @@ public class FileDialog : Dialog
         _tbPath.TextChanged += (s, e) => PathChanged ();
 
         _tableView.CellActivated += CellActivate;
-        _tableView.KeyUp += (s, k) => k.Handled = TableView_KeyUp (k);
+        _tableView.KeyDown += (s, k) => k.Handled = TableView_KeyUp (k);
         _tableView.SelectedCellChanged += TableView_SelectedCellChanged;
 
         _tableView.KeyBindings.ReplaceCommands (Key.Home, Command.Start);

+ 1 - 1
Terminal.Gui/Views/HexView.cs

@@ -452,7 +452,7 @@ public class HexView : View, IDesignable
     public virtual void OnPositionChanged () { PositionChanged?.Invoke (this, new HexViewEventArgs (Position, CursorPosition, BytesPerLine)); }
 
     /// <inheritdoc/>
-    public override bool OnProcessKeyDown (Key keyEvent)
+    protected override bool OnProcessKeyDown (Key keyEvent)
     {
         if (!AllowEdits)
         {

+ 1 - 1
Terminal.Gui/Views/ListView.cs

@@ -803,7 +803,7 @@ public class ListView : View, IDesignable
     }
 
     /// <inheritdoc/>
-    public override bool OnKeyDown (Key a)
+    protected override bool OnKeyDown (Key a)
     {
         // Enable user to find & select an item by typing text
         if (CollectionNavigatorBase.IsCompatibleKey (a) && (!AllowsMarking && a == Key.Space))

+ 1 - 1
Terminal.Gui/Views/ScrollView.cs

@@ -388,7 +388,7 @@ public class ScrollView : View
     }
 
     /// <inheritdoc/>
-    public override bool OnKeyDown (Key a)
+    protected override bool OnKeyDown (Key a)
     {
         if (base.OnKeyDown (a))
         {

+ 1 - 1
Terminal.Gui/Views/TableView/TableView.cs

@@ -988,7 +988,7 @@ public class TableView : View
     }
 
     /// <inheritdoc/>
-    public override bool OnKeyDown (Key key)
+    protected override bool OnKeyDown (Key key)
     {
         if (TableIsNullOrInvisible ())
         {

+ 1 - 1
Terminal.Gui/Views/TextField.cs

@@ -1055,7 +1055,7 @@ public class TextField : View
     /// </summary>
     /// <param name="a"></param>
     /// <returns></returns>
-    public override bool OnProcessKeyDown (Key a)
+    protected override bool OnProcessKeyDown (Key a)
     {
         // Remember the cursor position because the new calculated cursor position is needed
         // to be set BEFORE the TextChanged event is triggered.

+ 1 - 1
Terminal.Gui/Views/TextValidateField.cs

@@ -597,7 +597,7 @@ namespace Terminal.Gui
         }
 
         /// <inheritdoc/>
-        public override bool OnProcessKeyDown (Key a)
+        protected override bool OnProcessKeyDown (Key a)
         {
             if (_provider is null)
             {

+ 1 - 1
Terminal.Gui/Views/TextView.cs

@@ -3703,7 +3703,7 @@ public class TextView : View
     }
 
     /// <inheritdoc/>
-    public override bool OnProcessKeyDown (Key a)
+    protected override bool OnProcessKeyDown (Key a)
     {
         if (!CanFocus)
         {

+ 1 - 1
Terminal.Gui/Views/TileView.cs

@@ -286,7 +286,7 @@ public class TileView : View
 
     //// BUGBUG: Why is this not handled by a key binding???
     /// <inheritdoc/>
-    public override bool OnProcessKeyDown (Key keyEvent)
+    protected override bool OnProcessKeyDown (Key keyEvent)
     {
         var focusMoved = false;
 

+ 1 - 1
Terminal.Gui/Views/TimeField.cs

@@ -177,7 +177,7 @@ public class TimeField : TextField
     }
 
     /// <inheritdoc/>
-    public override bool OnProcessKeyDown (Key a)
+    protected override bool OnProcessKeyDown (Key a)
     {
         // Ignore non-numeric characters.
         if (a.KeyCode is >= (KeyCode)(int)KeyCode.D0 and <= (KeyCode)(int)KeyCode.D9)

+ 1 - 1
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -1182,7 +1182,7 @@ public class TreeView<T> : View, ITreeView where T : class
     }
 
     /// <inheritdoc/>
-    public override bool OnKeyDown (Key keyEvent)
+    protected override bool OnKeyDown (Key keyEvent)
     {
         if (!Enabled)
         {

+ 1 - 1
Terminal.Gui/Views/Wizard/Wizard.cs

@@ -386,7 +386,7 @@ public class Wizard : Dialog
     /// </summary>
     /// <param name="key"></param>
     /// <returns></returns>
-    public override bool OnProcessKeyDown (Key key)
+    protected override bool OnProcessKeyDown (Key key)
     {
         //// BUGBUG: Why is this not handled by a key binding???
         if (!Modal)

+ 2 - 2
UICatalog/Scenarios/LineDrawing.cs

@@ -121,7 +121,7 @@ public class LineDrawing : Scenario
         tools.CurrentColor = canvas.GetNormalColor ();
         canvas.CurrentAttribute = tools.CurrentColor;
 
-        win.KeyDown += (s, e) => { e.Handled = canvas.OnKeyDown (e); };
+        win.KeyDown += (s, e) => { e.Handled = canvas.NewKeyDownEvent (e); };
 
         Application.Run (win);
         win.Dispose ();
@@ -290,7 +290,7 @@ public class DrawingArea : View
     }
 
     //// BUGBUG: Why is this not handled by a key binding???
-    public override bool OnKeyDown (Key e)
+    protected override bool OnKeyDown (Key e)
     {
         // BUGBUG: These should be implemented with key bindings
         if (e.KeyCode == (KeyCode.Z | KeyCode.CtrlMask))

+ 1 - 1
UICatalog/Scenarios/Snake.cs

@@ -357,7 +357,7 @@ public class Snake : Scenario
         }
 
         // BUGBUG: Should (can) this use key bindings instead.
-        public override bool OnKeyDown (Key keyEvent)
+        protected override bool OnKeyDown (Key keyEvent)
         {
             if (keyEvent.KeyCode == KeyCode.CursorUp)
             {

+ 1 - 1
UICatalog/Scenarios/VkeyPacketSimulator.cs

@@ -112,7 +112,7 @@ public class VkeyPacketSimulator : Scenario
 
                                     if (handled == null || handled == false)
                                     {
-                                        if (!tvOutput.OnProcessKeyDown (e))
+                                        if (!tvOutput.NewKeyDownEvent (e))
                                         {
                                             Application.Invoke (
                                                                 () => MessageBox.Query (

+ 6 - 4
UnitTests/FileServices/FileDialogTests.cs

@@ -140,7 +140,7 @@ public class FileDialogTests ()
         AssertIsTheStartingDirectory (dlg.Path);
 
         Assert.IsType<TextField> (dlg.MostFocused);
-        Send ('v', ConsoleKey.DownArrow);
+        Application.OnKeyDown (Key.CursorDown);
 
         var tv = GetTableView(dlg);
         tv.SetFocus ();
@@ -152,15 +152,17 @@ public class FileDialogTests ()
         AssertIsTheStartingDirectory (dlg.Path);
 
         // Accept navigation up a directory
-        Send ('\n', ConsoleKey.Enter);
+        Application.OnKeyDown (Key.Enter);
 
         AssertIsTheRootDirectory (dlg.Path);
 
         Assert.True (dlg.Canceled);
         Assert.False (selected);
 
-        // Now press the back button (in table view)
-        Send ('<', ConsoleKey.Backspace);
+        Assert.IsType<TableView> (dlg.MostFocused);
+
+        // Now press Backspace (in table view)
+        Application.OnKeyDown (Key.Backspace);
 
         // Should move us back to the root
         AssertIsTheStartingDirectory (dlg.Path);

+ 5 - 5
UnitTests/Input/ResponderTests.cs

@@ -205,11 +205,11 @@ public class ResponderTests
         var r = new View ();
         var args = new Key { KeyCode = KeyCode.Null };
 
-        Assert.False (r.OnKeyDown (args));
+        Assert.False (r.NewKeyDownEvent (args));
         Assert.False (args.Handled);
 
         r.KeyDown += (s, a) => a.Handled = true;
-        Assert.True (r.OnKeyDown (args));
+        Assert.True (r.NewKeyDownEvent (args));
         Assert.True (args.Handled);
 
         r.Dispose ();
@@ -232,8 +232,8 @@ public class ResponderTests
         var r = new View ();
 
         //Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown }));
-        Assert.False (r.OnKeyDown (new Key { KeyCode = KeyCode.Null }));
-        Assert.False (r.OnKeyUp (new Key { KeyCode = KeyCode.Null }));
+        Assert.False (r.NewKeyDownEvent (new Key { KeyCode = KeyCode.Null }));
+        Assert.False (r.NewKeyDownEvent (new Key { KeyCode = KeyCode.Null }));
         Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
 
         var v = new View ();
@@ -293,6 +293,6 @@ public class ResponderTests
 
     public class DerivedView : View
     {
-        public override bool OnKeyDown (Key keyEvent) { return true; }
+        protected override bool OnKeyDown (Key keyEvent) { return true; }
     }
 }

+ 2 - 2
UnitTests/View/KeyboardEventTests.cs

@@ -463,7 +463,7 @@ public class KeyboardEventTests (ITestOutputHelper output) : TestsAllViews
             return CancelVirtualMethods;
         }
 
-        public override bool OnKeyDown (Key keyEvent)
+        protected override bool OnKeyDown (Key keyEvent)
         {
             OnKeyDownCalled = true;
 
@@ -477,7 +477,7 @@ public class KeyboardEventTests (ITestOutputHelper output) : TestsAllViews
             return CancelVirtualMethods;
         }
 
-        public override bool OnProcessKeyDown (Key keyEvent)
+        protected override bool OnProcessKeyDown (Key keyEvent)
         {
             if (base.OnProcessKeyDown (keyEvent))
             {

+ 4 - 4
UnitTests/View/ViewTests.cs

@@ -870,10 +870,10 @@ At 0,0
     {
         var r = new View ();
 
-        Assert.False (r.OnKeyDown (new () { KeyCode = KeyCode.Null }));
+        Assert.False (r.NewKeyDownEvent (Key.Empty));
 
         //Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown }));
-        Assert.False (r.OnKeyUp (new () { KeyCode = KeyCode.Null }));
+        Assert.False (r.NewKeyUpEvent (Key.Empty));
         Assert.False (r.NewMouseEvent (new () { Flags = MouseFlags.AllEvents }));
 
         r.Dispose ();
@@ -1132,7 +1132,7 @@ At 0,0
             ClearNeedsDisplay ();
         }
 
-        public override bool OnKeyDown (Key keyEvent)
+        protected override bool OnKeyDown (Key keyEvent)
         {
             IsKeyDown = true;
 
@@ -1146,7 +1146,7 @@ At 0,0
             return true;
         }
 
-        public override bool OnProcessKeyDown (Key keyEvent)
+        protected override bool OnProcessKeyDown (Key keyEvent)
         {
             IsKeyPress = true;
 

+ 65 - 65
UnitTests/Views/ScrollViewTests.cs

@@ -579,7 +579,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -603,7 +603,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -627,7 +627,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -651,7 +651,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -675,7 +675,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -699,7 +699,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -723,7 +723,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorRight));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorRight));
         top.Draw ();
 
         expected = @"
@@ -746,7 +746,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.End.WithCtrl));
+        Assert.True (scrollView.NewKeyDownEvent (Key.End.WithCtrl));
         top.Draw ();
 
         expected = @"
@@ -769,8 +769,8 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.Home.WithCtrl));
-        Assert.True (scrollView.OnKeyDown (Key.CursorDown));
+        Assert.True (scrollView.NewKeyDownEvent (Key.Home.WithCtrl));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
         top.Draw ();
 
         expected = @"
@@ -793,7 +793,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorDown));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
         top.Draw ();
 
         expected = @"
@@ -816,7 +816,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.CursorDown));
+        Assert.True (scrollView.NewKeyDownEvent (Key.CursorDown));
         top.Draw ();
 
         expected = @"
@@ -839,7 +839,7 @@ public class ScrollViewTests (ITestOutputHelper output)
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (1, 1, 21, 14), pos);
 
-        Assert.True (scrollView.OnKeyDown (Key.End));
+        Assert.True (scrollView.NewKeyDownEvent (Key.End));
         top.Draw ();
 
         expected = @"
@@ -940,120 +940,120 @@ public class ScrollViewTests (ITestOutputHelper output)
         Assert.True (sv.KeepContentAlwaysInViewport);
         Assert.True (sv.AutoHideScrollBars);
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorUp));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorDown));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorDown));
         Assert.Equal (new (0, -1), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorUp));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageUp));
+        Assert.False (sv.NewKeyDownEvent (Key.PageUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown));
         Point point0xMinus10 = new (0, -10);
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageDown));
+        Assert.False (sv.NewKeyDownEvent (Key.PageDown));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorDown));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorDown));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.V.WithAlt));
+        Assert.True (sv.NewKeyDownEvent (Key.V.WithAlt));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.V.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.V.WithCtrl));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorLeft));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorLeft));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorRight));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorRight));
         Assert.Equal (new (-1, -10), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorLeft));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorLeft));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.PageUp.WithCtrl));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown.WithCtrl));
         Point pointMinus20xMinus10 = new (-20, -10);
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorRight));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorRight));
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home));
+        Assert.True (sv.NewKeyDownEvent (Key.Home));
         Point pointMinus20x0 = new (-20, 0);
         Assert.Equal (pointMinus20x0, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.Home));
+        Assert.False (sv.NewKeyDownEvent (Key.Home));
         Assert.Equal (pointMinus20x0, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.End));
+        Assert.True (sv.NewKeyDownEvent (Key.End));
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.End));
+        Assert.False (sv.NewKeyDownEvent (Key.End));
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.Home.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.End.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.End.WithCtrl));
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.End.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.End.WithCtrl));
         Assert.Equal (pointMinus20xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home));
+        Assert.True (sv.NewKeyDownEvent (Key.Home));
         Assert.Equal (pointMinus20x0, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.Equal (Point.Empty, sv.ContentOffset);
 
         sv.KeepContentAlwaysInViewport = false;
         Assert.False (sv.KeepContentAlwaysInViewport);
         Assert.True (sv.AutoHideScrollBars);
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorUp));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorDown));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorDown));
         Assert.Equal (new (0, -1), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorUp));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageUp));
+        Assert.False (sv.NewKeyDownEvent (Key.PageUp));
         Assert.Equal (Point.Empty, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown));
         Assert.Equal (point0xMinus10, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown));
         Point point0xMinus19 = new (0, -19);
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageDown));
+        Assert.False (sv.NewKeyDownEvent (Key.PageDown));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorDown));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorDown));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.V.WithAlt));
+        Assert.True (sv.NewKeyDownEvent (Key.V.WithAlt));
         Assert.Equal (new (0, -9), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.V.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.V.WithCtrl));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorLeft));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorLeft));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorRight));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorRight));
         Assert.Equal (new (-1, -19), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.CursorLeft));
+        Assert.True (sv.NewKeyDownEvent (Key.CursorLeft));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.PageUp.WithCtrl));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown.WithCtrl));
         Assert.Equal (new (-20, -19), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.PageDown.WithCtrl));
         Point pointMinus39xMinus19 = new (-39, -19);
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.PageDown.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.PageDown.WithCtrl));
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.CursorRight));
+        Assert.False (sv.NewKeyDownEvent (Key.CursorRight));
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.PageUp.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.PageUp.WithCtrl));
         var pointMinus19xMinus19 = new Point (-19, -19);
         Assert.Equal (pointMinus19xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home));
+        Assert.True (sv.NewKeyDownEvent (Key.Home));
         Assert.Equal (new (-19, 0), sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.Home));
+        Assert.False (sv.NewKeyDownEvent (Key.Home));
         Assert.Equal (new (-19, 0), sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.End));
+        Assert.True (sv.NewKeyDownEvent (Key.End));
         Assert.Equal (pointMinus19xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.End));
+        Assert.False (sv.NewKeyDownEvent (Key.End));
         Assert.Equal (pointMinus19xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.Home.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.Home.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.Home.WithCtrl));
         Assert.Equal (point0xMinus19, sv.ContentOffset);
-        Assert.True (sv.OnKeyDown (Key.End.WithCtrl));
+        Assert.True (sv.NewKeyDownEvent (Key.End.WithCtrl));
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
-        Assert.False (sv.OnKeyDown (Key.End.WithCtrl));
+        Assert.False (sv.NewKeyDownEvent (Key.End.WithCtrl));
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
     }