Skip to content

Commit 80306c6

Browse files
authored
Fixes #3885. ableView's CollectionNavigator sometimes doesn't work right. (#3933)
1 parent df9549e commit 80306c6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Terminal.Gui/Text/TableCollectionNavigator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TableCollectionNavigator : CollectionNavigatorBase
1111
/// <inheritdoc/>
1212
protected override object ElementAt (int idx)
1313
{
14-
int col = tableView.SelectedColumn;
14+
int col = tableView.FullRowSelect ? 0 : tableView.SelectedColumn;
1515
object rawValue = tableView.Table [idx, col];
1616

1717
ColumnStyle style = tableView.Style.GetColumnStyleIfAny (col);

UnitTests/Views/TableViewTests.cs

+23
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,29 @@ public void CanTabOutOfTableViewUsingCursor_Left_ClearsSelectionFirst ()
33643364
Application.Top.Dispose ();
33653365
}
33663366

3367+
[Theory]
3368+
[InlineData (true, 0, 1)]
3369+
[InlineData (true, 1, 1)]
3370+
[InlineData (false, 0, 1)]
3371+
[InlineData (false, 1, 0)]
3372+
public void TableCollectionNavigator_FullRowSelect_True_False (bool fullRowSelect, int selectedCol, int expectedRow)
3373+
{
3374+
TableView tableView = new () { FullRowSelect = fullRowSelect, SelectedColumn = selectedCol};
3375+
tableView.BeginInit ();
3376+
tableView.EndInit ();
3377+
3378+
DataTable dt = new ();
3379+
dt.Columns.Add ("A");
3380+
dt.Columns.Add ("B");
3381+
3382+
dt.Rows.Add (1, 2);
3383+
dt.Rows.Add (3, 4);
3384+
tableView.Table = new DataTableSource (dt);
3385+
tableView.SelectedColumn = selectedCol;
3386+
3387+
Assert.Equal (expectedRow, tableView.CollectionNavigator.GetNextMatchingItem (0, "3".ToCharArray () [0]));
3388+
}
3389+
33673390
/// <summary>
33683391
/// Creates 3 views on <see cref="Application.Current"/> with the focus in the
33693392
/// <see cref="TableView"/>. This is a helper method to setup tests that want to

0 commit comments

Comments
 (0)