Skip to content

Commit

Permalink
fixed cell and row navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ahmad committed Dec 13, 2024
1 parent f831a80 commit 3b56c9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/WinUI.TableView/TableView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public partial class TableView
internal TableViewCellSlot? CurrentCellSlot { get; set; }
internal TableViewCellSlot? SelectionStartCellSlot { get; set; }
internal int? SelectionStartRowIndex { get; set; }
internal int? CurrentRowIndex { get; set; }
internal HashSet<TableViewCellSlot> SelectedCells { get; set; } = new HashSet<TableViewCellSlot>();
internal HashSet<HashSet<TableViewCellSlot>> SelectedCellRanges { get; } = new HashSet<HashSet<TableViewCellSlot>>();
internal bool IsEditing { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/WinUI.TableView/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey
else if ((e.Key is VirtualKey.Left or VirtualKey.Right or VirtualKey.Up or VirtualKey.Down)
&& !IsEditing)
{
var row = (LastSelectionUnit is TableViewSelectionUnit.Row ? SelectionStartRowIndex : SelectionStartCellSlot?.Row) ?? -1;
var row = (LastSelectionUnit is TableViewSelectionUnit.Row ? CurrentRowIndex : CurrentCellSlot?.Row) ?? -1;
var column = CurrentCellSlot?.Column ?? -1;

if (row == -1 && column == -1)
Expand Down Expand Up @@ -749,6 +749,7 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
{
var selectionRange = SelectedRanges.FirstOrDefault(x => x.IsInRange(slot.Row));
SelectionStartRowIndex ??= slot.Row;
CurrentRowIndex = slot.Row;

if (selectionRange is not null)
{
Expand Down
1 change: 1 addition & 0 deletions src/WinUI.TableView/TableViewRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected override void OnTapped(TappedRoutedEventArgs e)

if (TableView?.SelectionUnit is TableViewSelectionUnit.Row or TableViewSelectionUnit.CellOrRow)
{
TableView.CurrentRowIndex = Index;
TableView.LastSelectionUnit = TableViewSelectionUnit.Row;
}
}
Expand Down

0 comments on commit 3b56c9c

Please sign in to comment.