Просмотр исходного кода

Fixes #1959: GoToEnd should not fail on an empty TreeView (#1960)

Co-authored-by: Tig Kindel <[email protected]>
Juan Manuel Elosegui 2 лет назад
Родитель
Сommit
73846b3c32
2 измененных файлов с 10 добавлено и 1 удалено
  1. 1 1
      Terminal.Gui/Views/TreeView.cs
  2. 9 0
      UnitTests/TreeViewTests.cs

+ 1 - 1
Terminal.Gui/Views/TreeView.cs

@@ -907,7 +907,7 @@ namespace Terminal.Gui {
 		{
 		{
 			var map = BuildLineMap ();
 			var map = BuildLineMap ();
 			ScrollOffsetVertical = Math.Max (0, map.Count - Bounds.Height + 1);
 			ScrollOffsetVertical = Math.Max (0, map.Count - Bounds.Height + 1);
-			SelectedObject = map.Last ().Model;
+			SelectedObject = map.LastOrDefault ()?.Model;
 
 
 			SetNeedsDisplay ();
 			SetNeedsDisplay ();
 		}
 		}

+ 9 - 0
UnitTests/TreeViewTests.cs

@@ -543,6 +543,15 @@ namespace Terminal.Gui.Views {
 			Assert.Equal (1, tree.ScrollOffsetVertical);
 			Assert.Equal (1, tree.ScrollOffsetVertical);
 		}
 		}
 
 
+		[Fact]
+		public void GoToEnd_ShouldNotFailOnEmptyTreeView ()
+		{
+			var tree = new TreeView ();
+
+			var exception = Record.Exception (() => tree.GoToEnd ());
+
+			Assert.Null (exception);
+		}
 
 
 		[Fact]
 		[Fact]
 		public void ObjectActivated_CustomKey ()
 		public void ObjectActivated_CustomKey ()