Skip to content

Commit 1c8f606

Browse files
committedDec 31, 2022
Change Ctrl+Home/End to prevent horizontal navigation when FullRowSelect is on
1 parent 70ab6f5 commit 1c8f606

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed
 

‎Terminal.Gui/Views/TableView.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -794,22 +794,28 @@ public void PageDown(bool extend)
794794
}
795795

796796
/// <summary>
797-
/// Moves or extends the selection to the first cell in the table (0,0)
797+
/// Moves or extends the selection to the first cell in the table (0,0).
798+
/// If <see cref="FullRowSelect"/> is enabled then selection instead moves
799+
/// to (<see cref="SelectedColumn"/>,0) i.e. no horizontal scrolling.
798800
/// </summary>
799801
/// <param name="extend">true to extend the current selection (if any) instead of replacing</param>
800802
public void ChangeSelectionToStartOfTable (bool extend)
801803
{
802-
SetSelection (0, 0, extend);
804+
SetSelection (FullRowSelect ? SelectedColumn : 0, 0, extend);
803805
Update ();
804806
}
805807

806808
/// <summary>
807-
/// Moves or extends the selection to the final cell in the table
809+
/// Moves or extends the selection to the final cell in the table (nX,nY).
810+
/// If <see cref="FullRowSelect"/> is enabled then selection instead moves
811+
/// to (<see cref="SelectedColumn"/>,nY) i.e. no horizontal scrolling.
808812
/// </summary>
809813
/// <param name="extend">true to extend the current selection (if any) instead of replacing</param>
810814
public void ChangeSelectionToEndOfTable(bool extend)
811815
{
812-
SetSelection (Table.Columns.Count - 1, Table.Rows.Count - 1, extend);
816+
var finalColumn = Table.Columns.Count - 1;
817+
818+
SetSelection (FullRowSelect ? SelectedColumn : finalColumn, Table.Rows.Count - 1, extend);
813819
Update ();
814820
}
815821

‎UnitTests/TableViewTests.cs

+48
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,54 @@ public void TestColumnStyle_FirstColumnVisibleFalse_CursorStaysAt1(bool useHome)
13121312
Assert.Equal (1, tableView.SelectedColumn);
13131313
}
13141314

1315+
1316+
[InlineData(true)]
1317+
[InlineData (false)]
1318+
[Theory, AutoInitShutdown]
1319+
public void TestMoveStartEnd_WithFullRowSelect(bool withFullRowSelect)
1320+
{
1321+
var tableView = GetTwoRowSixColumnTable ();
1322+
tableView.FullRowSelect = withFullRowSelect;
1323+
1324+
tableView.SelectedRow = 1;
1325+
tableView.SelectedColumn = 1;
1326+
1327+
tableView.ProcessKey (new KeyEvent
1328+
{
1329+
Key = Key.Home | Key.CtrlMask
1330+
});
1331+
1332+
if(withFullRowSelect)
1333+
{
1334+
// Should not be any horizontal movement when
1335+
// using navigate to Start/End and FullRowSelect
1336+
Assert.Equal (1, tableView.SelectedColumn);
1337+
Assert.Equal (0, tableView.SelectedRow);
1338+
}
1339+
else
1340+
{
1341+
Assert.Equal (0, tableView.SelectedColumn);
1342+
Assert.Equal (0, tableView.SelectedRow);
1343+
}
1344+
1345+
tableView.ProcessKey (new KeyEvent
1346+
{
1347+
Key = Key.End | Key.CtrlMask
1348+
});
1349+
1350+
if(withFullRowSelect)
1351+
{
1352+
Assert.Equal (1, tableView.SelectedColumn);
1353+
Assert.Equal (1, tableView.SelectedRow);
1354+
}
1355+
else
1356+
{
1357+
Assert.Equal (5, tableView.SelectedColumn);
1358+
Assert.Equal (1, tableView.SelectedRow);
1359+
}
1360+
1361+
}
1362+
13151363
[InlineData (true)]
13161364
[InlineData (false)]
13171365
[Theory, AutoInitShutdown]

0 commit comments

Comments
 (0)
Please sign in to comment.