Skip to content

Commit 3adfa22

Browse files
authored
Merge pull request #2263 from tznind/full-row-select-home-end
Fixes #2262 - Change Ctrl+Home/End to prevent horizontal navigation when FullRowSelect is on
2 parents b213afc + 1c8f606 commit 3adfa22

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
@@ -829,22 +829,28 @@ public void PageDown(bool extend)
829829
}
830830

831831
/// <summary>
832-
/// Moves or extends the selection to the first cell in the table (0,0)
832+
/// Moves or extends the selection to the first cell in the table (0,0).
833+
/// If <see cref="FullRowSelect"/> is enabled then selection instead moves
834+
/// to (<see cref="SelectedColumn"/>,0) i.e. no horizontal scrolling.
833835
/// </summary>
834836
/// <param name="extend">true to extend the current selection (if any) instead of replacing</param>
835837
public void ChangeSelectionToStartOfTable (bool extend)
836838
{
837-
SetSelection (0, 0, extend);
839+
SetSelection (FullRowSelect ? SelectedColumn : 0, 0, extend);
838840
Update ();
839841
}
840842

841843
/// <summary>
842-
/// Moves or extends the selection to the final cell in the table
844+
/// Moves or extends the selection to the final cell in the table (nX,nY).
845+
/// If <see cref="FullRowSelect"/> is enabled then selection instead moves
846+
/// to (<see cref="SelectedColumn"/>,nY) i.e. no horizontal scrolling.
843847
/// </summary>
844848
/// <param name="extend">true to extend the current selection (if any) instead of replacing</param>
845849
public void ChangeSelectionToEndOfTable(bool extend)
846850
{
847-
SetSelection (Table.Columns.Count - 1, Table.Rows.Count - 1, extend);
851+
var finalColumn = Table.Columns.Count - 1;
852+
853+
SetSelection (FullRowSelect ? SelectedColumn : finalColumn, Table.Rows.Count - 1, extend);
848854
Update ();
849855
}
850856

UnitTests/TableViewTests.cs

+48
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,54 @@ public void TestColumnStyle_FirstColumnVisibleFalse_CursorStaysAt1(bool useHome)
13811381
Assert.Equal (1, tableView.SelectedColumn);
13821382
}
13831383

1384+
1385+
[InlineData(true)]
1386+
[InlineData (false)]
1387+
[Theory, AutoInitShutdown]
1388+
public void TestMoveStartEnd_WithFullRowSelect(bool withFullRowSelect)
1389+
{
1390+
var tableView = GetTwoRowSixColumnTable ();
1391+
tableView.FullRowSelect = withFullRowSelect;
1392+
1393+
tableView.SelectedRow = 1;
1394+
tableView.SelectedColumn = 1;
1395+
1396+
tableView.ProcessKey (new KeyEvent
1397+
{
1398+
Key = Key.Home | Key.CtrlMask
1399+
});
1400+
1401+
if(withFullRowSelect)
1402+
{
1403+
// Should not be any horizontal movement when
1404+
// using navigate to Start/End and FullRowSelect
1405+
Assert.Equal (1, tableView.SelectedColumn);
1406+
Assert.Equal (0, tableView.SelectedRow);
1407+
}
1408+
else
1409+
{
1410+
Assert.Equal (0, tableView.SelectedColumn);
1411+
Assert.Equal (0, tableView.SelectedRow);
1412+
}
1413+
1414+
tableView.ProcessKey (new KeyEvent
1415+
{
1416+
Key = Key.End | Key.CtrlMask
1417+
});
1418+
1419+
if(withFullRowSelect)
1420+
{
1421+
Assert.Equal (1, tableView.SelectedColumn);
1422+
Assert.Equal (1, tableView.SelectedRow);
1423+
}
1424+
else
1425+
{
1426+
Assert.Equal (5, tableView.SelectedColumn);
1427+
Assert.Equal (1, tableView.SelectedRow);
1428+
}
1429+
1430+
}
1431+
13841432
[InlineData (true)]
13851433
[InlineData (false)]
13861434
[Theory, AutoInitShutdown]

0 commit comments

Comments
 (0)