浏览代码

Fixes #3885. ableView's CollectionNavigator sometimes doesn't work right. (#3933)

BDisp 5 月之前
父节点
当前提交
80306c64c3
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. 1 1
      Terminal.Gui/Text/TableCollectionNavigator.cs
  2. 23 0
      UnitTests/Views/TableViewTests.cs

+ 1 - 1
Terminal.Gui/Text/TableCollectionNavigator.cs

@@ -11,7 +11,7 @@ public class TableCollectionNavigator : CollectionNavigatorBase
     /// <inheritdoc/>
     /// <inheritdoc/>
     protected override object ElementAt (int idx)
     protected override object ElementAt (int idx)
     {
     {
-        int col = tableView.SelectedColumn;
+        int col = tableView.FullRowSelect ? 0 : tableView.SelectedColumn;
         object rawValue = tableView.Table [idx, col];
         object rawValue = tableView.Table [idx, col];
 
 
         ColumnStyle style = tableView.Style.GetColumnStyleIfAny (col);
         ColumnStyle style = tableView.Style.GetColumnStyleIfAny (col);

+ 23 - 0
UnitTests/Views/TableViewTests.cs

@@ -3364,6 +3364,29 @@ A B C
         Application.Top.Dispose ();
         Application.Top.Dispose ();
     }
     }
 
 
+    [Theory]
+    [InlineData (true, 0, 1)]
+    [InlineData (true, 1, 1)]
+    [InlineData (false, 0, 1)]
+    [InlineData (false, 1, 0)]
+    public void TableCollectionNavigator_FullRowSelect_True_False (bool fullRowSelect, int selectedCol, int expectedRow)
+    {
+        TableView tableView = new () { FullRowSelect = fullRowSelect, SelectedColumn = selectedCol};
+        tableView.BeginInit ();
+        tableView.EndInit ();
+
+        DataTable dt = new ();
+        dt.Columns.Add ("A");
+        dt.Columns.Add ("B");
+
+        dt.Rows.Add (1, 2);
+        dt.Rows.Add (3, 4);
+        tableView.Table = new DataTableSource (dt);
+        tableView.SelectedColumn = selectedCol;
+
+        Assert.Equal (expectedRow, tableView.CollectionNavigator.GetNextMatchingItem (0, "3".ToCharArray () [0]));
+    }
+
     /// <summary>
     /// <summary>
     /// Creates 3 views on <see cref="Application.Current"/> with the focus in the
     /// Creates 3 views on <see cref="Application.Current"/> with the focus in the
     /// <see cref="TableView"/>.  This is a helper method to setup tests that want to
     /// <see cref="TableView"/>.  This is a helper method to setup tests that want to