diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 0fcd73b07..7cafe2ad8 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -3080,12 +3080,17 @@ namespace Terminal.Gui { /// The view. /// The method name. /// if it's overridden, otherwise. - public bool IsOverridden (View view, string method) + public static bool IsOverridden (View view, string method) { - Type t = view.GetType (); - MethodInfo m = t.GetMethod (method); - - return (m.DeclaringType == t || m.ReflectedType == t) && m.GetBaseDefinition ().DeclaringType == typeof (Responder); + MethodInfo m = view.GetType ().GetMethod (method, + BindingFlags.Instance + | BindingFlags.Public + | BindingFlags.NonPublic + | BindingFlags.DeclaredOnly); + if (m == null) { + return false; + } + return m.GetBaseDefinition ().DeclaringType != m.DeclaringType; } } } diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index c26a340ed..173dc188d 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -484,7 +484,7 @@ namespace Terminal.Gui { search.SetFocus (); } - search.CursorPosition = search.Text.RuneCount; + search.CursorPosition = search.Text.ConsoleWidth; return base.OnEnter (view); } diff --git a/UnitTests/ComboBoxTests.cs b/UnitTests/ComboBoxTests.cs index bf5b385c0..41adc4b40 100644 --- a/UnitTests/ComboBoxTests.cs +++ b/UnitTests/ComboBoxTests.cs @@ -826,9 +826,9 @@ Three ", output); TestHelpers.AssertDriverColorsAre (@" 000000 -00000 -22222 -22222", attributes); +222222 +222222 +222222", attributes); Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); Assert.Equal ("", selected); @@ -838,9 +838,9 @@ Three ", output); cb.Redraw (cb.Bounds); TestHelpers.AssertDriverColorsAre (@" 000000 -22222 -00000 -22222", attributes); +222222 +000002 +222222", attributes); Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); Assert.Equal ("", selected); @@ -850,9 +850,9 @@ Three ", output); cb.Redraw (cb.Bounds); TestHelpers.AssertDriverColorsAre (@" 000000 -22222 -22222 -00000", attributes); +222222 +222222 +000002", attributes); Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); Assert.Equal ("Three", selected); @@ -868,9 +868,9 @@ Three ", output); cb.Redraw (cb.Bounds); TestHelpers.AssertDriverColorsAre (@" 000000 -22222 -22222 -00000", attributes); +222222 +222222 +000002", attributes); Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); Assert.Equal ("Three", selected); @@ -880,9 +880,9 @@ Three ", output); cb.Redraw (cb.Bounds); TestHelpers.AssertDriverColorsAre (@" 000000 -22222 -00000 -11111", attributes); +222222 +000002 +111112", attributes); Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); Assert.Equal ("Three", selected); @@ -892,9 +892,9 @@ Three ", output); cb.Redraw (cb.Bounds); TestHelpers.AssertDriverColorsAre (@" 000000 -00000 -22222 -11111", attributes); +000002 +222222 +111112", attributes); Assert.True (cb.ProcessKey (new KeyEvent (Key.F4, new KeyModifiers ()))); Assert.Equal ("Three", selected); diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index e2a20e80b..03969c4a7 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -4062,5 +4062,29 @@ This is a tes Assert.False (view.IsKeyPress); Assert.True (view.IsKeyUp); } + + [Fact, AutoInitShutdown] + public void IsOverridden_False_IfNotOverriden () + { + var view = new DerivedView () { Text = "DerivedView does not override MouseEvent", Width = 10, Height = 10 }; + + Assert.False (View.IsOverridden (view, "MouseEvent")); + + var view2 = new Button () { Text = "Button does not overrides OnKeyDown", Width = 10, Height = 10 }; + + Assert.False (View.IsOverridden (view2, "OnKeyDown")); + } + + [Fact, AutoInitShutdown] + public void IsOverridden_True_IfOverriden () + { + var view = new Button () { Text = "Button overrides MouseEvent", Width = 10, Height = 10 }; + + Assert.True (View.IsOverridden (view, "MouseEvent")); + + var view2 = new DerivedView () { Text = "DerivedView overrides OnKeyDown", Width = 10, Height = 10 }; + + Assert.True (View.IsOverridden (view2, "OnKeyDown")); + } } }