Skip to content

Commit 8cebdf5

Browse files
Discard changes to src/TableView.cs
1 parent e77fe69 commit 8cebdf5

1 file changed

Lines changed: 1 addition & 127 deletions

File tree

src/TableView.cs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using CommunityToolkit.WinUI;
1+
using CommunityToolkit.WinUI;
22
using Microsoft.UI;
33
using Microsoft.UI.Xaml;
44
using Microsoft.UI.Xaml.Controls;
55
using Microsoft.UI.Xaml.Controls.Primitives;
66
using Microsoft.UI.Xaml.Data;
77
using Microsoft.UI.Xaml.Input;
8-
using Microsoft.UI.Xaml.Media;
98
using System;
109
using System.Collections;
1110
using System.Collections.Generic;
@@ -79,11 +78,6 @@ private void TableView_SelectionChanged(object sender, SelectionChangedEventArgs
7978
CurrentCellSlot = null;
8079
OnCellSelectionChanged();
8180

82-
if (IsRowKeyboardContext)//Keeps alignment with base ListView selection
83-
{
84-
CurrentRowIndex = SelectedIndex;
85-
}
86-
8781
if (SelectedItems?.Count == 1)
8882
{
8983
DispatcherQueue.TryEnqueue(async () => await ScrollRowIntoView(SelectedIndex));
@@ -118,12 +112,6 @@ protected override DependencyObject GetContainerForItemOverride()
118112
return row;
119113
}
120114

121-
private bool IsRowKeyboardContext =>
122-
(UseListViewHotkeys == true) && //Not sure if I'm solving a bug or adding a feature, so I've made it apply only when the UseListViewHotkeys is set to true just in case.
123-
(SelectionUnit == TableViewSelectionUnit.Row ||
124-
(SelectionUnit == TableViewSelectionUnit.CellOrRow &&
125-
LastSelectionUnit == TableViewSelectionUnit.Row));
126-
127115
/// <inheritdoc/>
128116
protected override async void OnKeyDown(KeyRoutedEventArgs e)
129117
{
@@ -136,95 +124,9 @@ protected override async void OnKeyDown(KeyRoutedEventArgs e)
136124
return;
137125
}
138126

139-
if (!IsEditing && IsRowKeyboardContext)
140-
{
141-
if (!shiftKey &&
142-
!ctrlKey &&
143-
SelectionMode == ListViewSelectionMode.Multiple &&
144-
e.Key == VirtualKey.Enter)
145-
{
146-
ToggleCurrentRowSelection();
147-
e.Handled = true;
148-
return;
149-
}
150-
151-
var rowSelectionOnly = SelectionUnit == TableViewSelectionUnit.Row;
152-
153-
if (e.Key is VirtualKey.Up or VirtualKey.Down or
154-
VirtualKey.Home or VirtualKey.End or
155-
VirtualKey.PageUp or VirtualKey.PageDown ||
156-
(rowSelectionOnly && (e.Key is VirtualKey.Left or VirtualKey.Right)))
157-
{
158-
int? prevCellRow = null;
159-
if (SelectionUnit == TableViewSelectionUnit.Row && CurrentCellSlot.HasValue)
160-
{
161-
prevCellRow = CurrentCellSlot.Value.Row;
162-
}
163-
164-
base.OnKeyDown(e); // Let ListView move the row focus / selection
165-
166-
var focusedIndex = GetFocusedRowIndex();
167-
if (focusedIndex >= 0)
168-
{
169-
CurrentRowIndex = focusedIndex;
170-
SelectionStartRowIndex ??= focusedIndex;
171-
}
172-
173-
if (SelectionUnit == TableViewSelectionUnit.Row &&
174-
prevCellRow.HasValue &&
175-
focusedIndex >= 0 &&
176-
focusedIndex != prevCellRow.Value)
177-
{
178-
CurrentCellSlot = null; // will un-apply old cell's current-state border
179-
}
180-
return;
181-
}
182-
}
183-
// Everything else (cell nav, F2 in cell mode, Space, etc.)
184127
await HandleNavigations(e, shiftKey, ctrlKey);
185128
}
186129

187-
188-
189-
private void ToggleCurrentRowSelection()
190-
{
191-
192-
var index = GetFocusedRowIndex();
193-
194-
if (index < 0)
195-
{
196-
var rowIndex = CurrentRowIndex ?? SelectedIndex;
197-
198-
if (rowIndex is < 0 || rowIndex >= Items.Count)
199-
{
200-
return;
201-
}
202-
203-
index = rowIndex;
204-
}
205-
206-
207-
if (index < 0 || index >= Items.Count) { return;}
208-
209-
var isSelected = SelectedRanges.Any(r => r.IsInRange(index));
210-
211-
var singleIndexRange = new ItemIndexRange(index, 1u);
212-
213-
if (isSelected)
214-
{
215-
DeselectRange(singleIndexRange);
216-
}
217-
else
218-
{
219-
SelectRange(singleIndexRange);
220-
}
221-
222-
SelectionStartRowIndex = index;
223-
CurrentRowIndex = index;
224-
225-
}
226-
227-
228130
/// <summary>
229131
/// Handles navigation keys.
230132
/// </summary>
@@ -352,34 +254,6 @@ private bool HandleShortKeys(bool shiftKey, bool ctrlKey, VirtualKey key)
352254
return false;
353255
}
354256

355-
private int GetFocusedRowIndex()
356-
{
357-
if (XamlRoot is null)
358-
return -1;
359-
360-
var focused = FocusManager.GetFocusedElement(XamlRoot) as DependencyObject;
361-
if (focused is null)
362-
return -1;
363-
364-
var row = GetRowFromElement(focused);
365-
return row?.Index ?? -1;
366-
}
367-
368-
private static TableViewRow? GetRowFromElement(DependencyObject element)
369-
{
370-
var current = element;
371-
372-
while (current is not null)
373-
{
374-
if (current is TableViewRow row)
375-
return row;
376-
377-
current = VisualTreeHelper.GetParent(current);
378-
}
379-
380-
return null;
381-
}
382-
383257
/// <inheritdoc/>
384258
protected async override void OnApplyTemplate()
385259
{

0 commit comments

Comments
 (0)