浏览代码

TrySplitTile moves Title across to new child too

tznind 2 年之前
父节点
当前提交
45e2218e37
共有 2 个文件被更改,包括 16 次插入1 次删除
  1. 4 1
      Terminal.Gui/Views/TileView.cs
  2. 12 0
      UnitTests/TileViewTests.cs

+ 4 - 1
Terminal.Gui/Views/TileView.cs

@@ -419,7 +419,6 @@ namespace Terminal.Gui {
 			// the title too
 			var tile = tiles [idx];
 
-			// TODO: migrate the title too right?
 			var title = tile.Title;
 			View toMove = tile.View;
 
@@ -450,6 +449,10 @@ namespace Terminal.Gui {
 				newTileView1.Add (childView);
 			}
 
+			// Move the title across too
+			newContainer.tiles [0].Title = title;
+			tile.Title = string.Empty;
+
 			result = newContainer;
 			return true;
 		}

+ 12 - 0
UnitTests/TileViewTests.cs

@@ -1637,7 +1637,19 @@ namespace UnitTests {
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 		}
+		[Fact, AutoInitShutdown]
+		public void TestTrySplit_ShouldRetainTitle ()
+		{
+			var tv = new TileView ();
+			tv.Tiles.ElementAt (0).Title = "flibble";
+			tv.TrySplitTile (0, 2, out var subTileView);
 
+			// We moved the content so the title should also have been moved
+			Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
+
+			// Secondly we should have cleared the old title (it should have been moved not copied)
+			Assert.Empty (tv.Tiles.ElementAt (0).Title);
+		}
 
 
 		[Fact, AutoInitShutdown]