Skip to content

Commit 05a9894

Browse files
authored
Fix text selection when renaming (#7455)
1 parent fb209b0 commit 05a9894

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/Files/UserControls/Selection/RectangleSelection_ListViewBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private void RectangleSelection_PointerReleased(object sender, PointerRoutedEven
186186
selectionChanged(sender, null);
187187
}
188188
}
189-
//if (selectionState == SelectionState.Active)
189+
if (selectionState == SelectionState.Active || e.OriginalSource is ListViewBase)
190190
{
191191
// Always trigger SelectionEnded to focus the file list when clicking on the empty space (#2977)
192192
OnSelectionEnded();

src/Files/Views/LayoutModes/ColumnViewBase.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
161161
base.OnNavigatingFrom(e);
162162
}
163163

164-
private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
164+
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
165165
{
166-
await Task.Delay(200);
167166
FileList.Focus(FocusState.Programmatic);
168167
}
169168

@@ -268,6 +267,10 @@ private void EndRename(TextBox textBox)
268267
textBox.KeyDown -= RenameTextBox_KeyDown;
269268
FileNameTeachingTip.IsOpen = false;
270269
IsRenamingItem = false;
270+
271+
// Re-focus selected list item
272+
ListViewItem listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
273+
listViewItem?.Focus(FocusState.Programmatic);
271274
}
272275

273276
public override void ResetItemOpacity()

src/Files/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
282282
ParentShellPageInstance.FilesystemViewModel.PageTypeUpdated -= FilesystemViewModel_PageTypeUpdated;
283283
}
284284

285-
private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
285+
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
286286
{
287-
await Task.Delay(200);
288287
FileList.Focus(FocusState.Programmatic);
289288
}
290289

@@ -400,14 +399,14 @@ private async void CommitRename(TextBox textBox)
400399

401400
private void EndRename(TextBox textBox)
402401
{
403-
ListViewItem gridViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
404-
if (textBox == null || gridViewItem == null)
402+
ListViewItem listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
403+
if (textBox == null || listViewItem == null)
405404
{
406405
// Navigating away, do nothing
407406
}
408407
else
409408
{
410-
TextBlock textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;
409+
TextBlock textBlock = listViewItem.FindDescendant("ItemName") as TextBlock;
411410
textBox.Visibility = Visibility.Collapsed;
412411
textBlock.Visibility = Visibility.Visible;
413412
}
@@ -416,6 +415,9 @@ private void EndRename(TextBox textBox)
416415
textBox.KeyDown -= RenameTextBox_KeyDown;
417416
FileNameTeachingTip.IsOpen = false;
418417
IsRenamingItem = false;
418+
419+
// Re-focus selected list item
420+
listViewItem?.Focus(FocusState.Programmatic);
419421
}
420422

421423
private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

src/Files/Views/LayoutModes/GridViewBrowser.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
169169
FolderSettings.GridViewSizeChangeRequested -= FolderSettings_GridViewSizeChangeRequested;
170170
}
171171

172-
private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
172+
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
173173
{
174-
await Task.Delay(200);
175174
FileList.Focus(FocusState.Programmatic);
176175
}
177176

@@ -359,6 +358,10 @@ private void EndRename(TextBox textBox)
359358
textBox.KeyDown -= RenameTextBox_KeyDown;
360359
FileNameTeachingTip.IsOpen = false;
361360
IsRenamingItem = false;
361+
362+
// Re-focus selected list item
363+
GridViewItem gridViewItem = FileList.ContainerFromItem(RenamingItem) as GridViewItem;
364+
gridViewItem?.Focus(FocusState.Programmatic);
362365
}
363366

364367
private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

0 commit comments

Comments
 (0)