From 80306c64c3ccd4786194dcb59544edbf371c0958 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 28 Feb 2025 03:55:38 +0000 Subject: [PATCH] Fixes #3885. ableView's CollectionNavigator sometimes doesn't work right. (#3933) --- Terminal.Gui/Text/TableCollectionNavigator.cs | 2 +- UnitTests/Views/TableViewTests.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Text/TableCollectionNavigator.cs b/Terminal.Gui/Text/TableCollectionNavigator.cs index cc20129ff..002bd6a8d 100644 --- a/Terminal.Gui/Text/TableCollectionNavigator.cs +++ b/Terminal.Gui/Text/TableCollectionNavigator.cs @@ -11,7 +11,7 @@ public class TableCollectionNavigator : CollectionNavigatorBase /// protected override object ElementAt (int idx) { - int col = tableView.SelectedColumn; + int col = tableView.FullRowSelect ? 0 : tableView.SelectedColumn; object rawValue = tableView.Table [idx, col]; ColumnStyle style = tableView.Style.GetColumnStyleIfAny (col); diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 6cceed034..54793cf15 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -3364,6 +3364,29 @@ A B C 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])); + } + /// /// Creates 3 views on with the focus in the /// . This is a helper method to setup tests that want to