mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Add TableView navigation by letter using CollectionNavigator
This commit is contained in:
@@ -125,6 +125,13 @@ namespace Terminal.Gui {
|
||||
if (this.tableView.SelectedRow <= 0) {
|
||||
this.NavigateIf (k, Key.CursorUp, this.tbPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.tableView.HasFocus && char.IsLetterOrDigit((char)k.KeyEvent.KeyValue))
|
||||
{
|
||||
CycleToNextTableEntryBeginningWith(k);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -216,6 +223,46 @@ namespace Terminal.Gui {
|
||||
this.Add (this.btnToggleSplitterCollapse);
|
||||
}
|
||||
|
||||
private void CycleToNextTableEntryBeginningWith (KeyEventEventArgs keyEvent)
|
||||
{
|
||||
if(tableView.Table.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var collection = tableView
|
||||
.Table
|
||||
.Rows
|
||||
.Cast<DataRow>()
|
||||
.Select((o,idx)=>RowToStats(idx))
|
||||
.Select(s=>s.FileSystemInfo.Name)
|
||||
.ToArray();
|
||||
|
||||
var collectionNavigator = new CollectionNavigator(collection);
|
||||
|
||||
var row = tableView.SelectedRow;
|
||||
|
||||
// There is a multi select going on and not just for the current row
|
||||
if(tableView.GetAllSelectedCells().Any(c=>c.Y != row))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(tableView.Table.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int match = collectionNavigator.GetNextMatchingItem(row,(char)keyEvent.KeyEvent.KeyValue);
|
||||
|
||||
if(match != -1)
|
||||
{
|
||||
tableView.SelectedRow = match;
|
||||
tableView.EnsureValidSelection();
|
||||
tableView.EnsureSelectedCellIsVisible();
|
||||
keyEvent.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to use Utc dates for date modified.
|
||||
/// Defaults to <see langword="false"/>.
|
||||
@@ -782,7 +829,6 @@ namespace Terminal.Gui {
|
||||
|
||||
this.sorter.ApplySort ();
|
||||
this.tableView.Update ();
|
||||
|
||||
}
|
||||
private void BuildRow (int idx)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user