Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3080,12 +3080,17 @@ public View GetTopSuperView ()
/// <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)
{
Type t = view.GetType ();
MethodInfo m = t.GetMethod (method);

return (m.DeclaringType == t || m.ReflectedType == t) && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
public static bool IsOverridden (View view, string method)
{
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;
}
}
}
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public override bool OnEnter (View view)
search.SetFocus ();
}

search.CursorPosition = search.Text.RuneCount;
search.CursorPosition = search.Text.ConsoleWidth;

return base.OnEnter (view);
}
Expand Down
36 changes: 18 additions & 18 deletions UnitTests/ComboBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,9 @@ cb.Subviews [1].GetNormalColor ()

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);
Expand All @@ -838,9 +838,9 @@ cb.Subviews [1].GetNormalColor ()
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);
Expand All @@ -850,9 +850,9 @@ cb.Subviews [1].GetNormalColor ()
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);
Expand All @@ -868,9 +868,9 @@ cb.Subviews [1].GetNormalColor ()
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);
Expand All @@ -880,9 +880,9 @@ cb.Subviews [1].GetNormalColor ()
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);
Expand All @@ -892,9 +892,9 @@ cb.Subviews [1].GetNormalColor ()
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);
Expand Down
24 changes: 24 additions & 0 deletions UnitTests/ViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4062,5 +4062,29 @@ public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool a
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"));
}
}
}