소스 검색

Merge pull request #4 from BDisp/fixes_2140_onselectedchange

Fixes 2140 onselectedchange per @tig
Tig 2 년 전
부모
커밋
8f5f151135
4개의 변경된 파일54개의 추가작업 그리고 25개의 파일을 삭제
  1. 11 6
      Terminal.Gui/Core/View.cs
  2. 1 1
      Terminal.Gui/Views/ComboBox.cs
  3. 18 18
      UnitTests/ComboBoxTests.cs
  4. 24 0
      UnitTests/ViewTests.cs

+ 11 - 6
Terminal.Gui/Core/View.cs

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

+ 1 - 1
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);
 		}

+ 18 - 18
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);

+ 24 - 0
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"));
+		}
 	}
 }