瀏覽代碼

Changed to GetToplevelSubviews and removed unnecessary parameter from FocusNearestView.

BDisp 5 年之前
父節點
當前提交
e8305ae04c
共有 1 個文件被更改,包括 31 次插入3 次删除
  1. 31 3
      Terminal.Gui/Core/Toplevel.cs

+ 31 - 3
Terminal.Gui/Core/Toplevel.cs

@@ -153,7 +153,7 @@ namespace Terminal.Gui {
 					old?.SetNeedsDisplay ();
 					Focused?.SetNeedsDisplay ();
 				} else {
-					FocusNearestView (GetSuperViewSubviews (true), true);
+					FocusNearestView (GetToplevelSubviews (true));
 				}
 				return true;
 			case Key.CursorLeft:
@@ -166,7 +166,7 @@ namespace Terminal.Gui {
 					old?.SetNeedsDisplay ();
 					Focused?.SetNeedsDisplay ();
 				} else {
-					FocusNearestView (GetSuperViewSubviews (false), false);
+					FocusNearestView (GetToplevelSubviews (false));
 				}
 				return true;
 
@@ -178,7 +178,35 @@ namespace Terminal.Gui {
 			return false;
 		}
 
-		///<inheritdoc/>
+		IEnumerable<View> GetToplevelSubviews (bool isForward)
+		{
+			HashSet<View> views = new HashSet<View> ();
+
+			foreach (var v in SuperView.Subviews) {
+				views.Add (v);
+			}
+
+			return isForward ? views : views.Reverse ();
+		}
+
+		void FocusNearestView (IEnumerable<View> views)
+		{
+			bool found = false;
+
+			foreach (var v in views) {
+				if (v == this) {
+					found = true;
+				}
+				if (found && v != this) {
+					v.EnsureFocus ();
+					if (SuperView.Focused != null && SuperView.Focused != this) {
+						return;
+					}
+				}
+			}
+		}
+
+		///<inheritdoc cref="Add"/>
 		public override void Add (View view)
 		{
 			if (this == Application.Top) {