Merge pull request #4 from BDisp/fixes_2140_onselectedchange

Fixes 2140 onselectedchange per @tig
This commit is contained in:
Tig
2022-11-02 14:40:52 -07:00
committed by GitHub
4 changed files with 53 additions and 24 deletions

View File

@@ -3080,12 +3080,17 @@ namespace Terminal.Gui {
/// <param name="view">The view.</param>
/// <param name="method">The method name.</param>
/// <returns><see langword="true"/> if it's overridden, <see langword="false"/> otherwise.</returns>
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;
}
}
}

View File

@@ -484,7 +484,7 @@ namespace Terminal.Gui {
search.SetFocus ();
}
search.CursorPosition = search.Text.RuneCount;
search.CursorPosition = search.Text.ConsoleWidth;
return base.OnEnter (view);
}

View File

@@ -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);

View File

@@ -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"));
}
}
}