Skip to content

Fix text selection when renaming #7455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void RectangleSelection_PointerReleased(object sender, PointerRoutedEven
selectionChanged(sender, null);
}
}
//if (selectionState == SelectionState.Active)
if (selectionState == SelectionState.Active || e.OriginalSource is ListViewBase)
{
// Always trigger SelectionEnded to focus the file list when clicking on the empty space (#2977)
OnSelectionEnded();
Expand Down
7 changes: 5 additions & 2 deletions src/Files/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
base.OnNavigatingFrom(e);
}

private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
{
await Task.Delay(200);
FileList.Focus(FocusState.Programmatic);
}

Expand Down Expand Up @@ -268,6 +267,10 @@ private void EndRename(TextBox textBox)
textBox.KeyDown -= RenameTextBox_KeyDown;
FileNameTeachingTip.IsOpen = false;
IsRenamingItem = false;

// Re-focus selected list item
ListViewItem listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
listViewItem?.Focus(FocusState.Programmatic);
}

public override void ResetItemOpacity()
Expand Down
12 changes: 7 additions & 5 deletions src/Files/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
ParentShellPageInstance.FilesystemViewModel.PageTypeUpdated -= FilesystemViewModel_PageTypeUpdated;
}

private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
{
await Task.Delay(200);
FileList.Focus(FocusState.Programmatic);
}

Expand Down Expand Up @@ -400,14 +399,14 @@ private async void CommitRename(TextBox textBox)

private void EndRename(TextBox textBox)
{
ListViewItem gridViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
if (textBox == null || gridViewItem == null)
ListViewItem listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
if (textBox == null || listViewItem == null)
{
// Navigating away, do nothing
}
else
{
TextBlock textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;
TextBlock textBlock = listViewItem.FindDescendant("ItemName") as TextBlock;
textBox.Visibility = Visibility.Collapsed;
textBlock.Visibility = Visibility.Visible;
}
Expand All @@ -416,6 +415,9 @@ private void EndRename(TextBox textBox)
textBox.KeyDown -= RenameTextBox_KeyDown;
FileNameTeachingTip.IsOpen = false;
IsRenamingItem = false;

// Re-focus selected list item
listViewItem?.Focus(FocusState.Programmatic);
}

private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
Expand Down
7 changes: 5 additions & 2 deletions src/Files/Views/LayoutModes/GridViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
FolderSettings.GridViewSizeChangeRequested -= FolderSettings_GridViewSizeChangeRequested;
}

private async void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
private void SelectionRectangle_SelectionEnded(object sender, EventArgs e)
{
await Task.Delay(200);
FileList.Focus(FocusState.Programmatic);
}

Expand Down Expand Up @@ -359,6 +358,10 @@ private void EndRename(TextBox textBox)
textBox.KeyDown -= RenameTextBox_KeyDown;
FileNameTeachingTip.IsOpen = false;
IsRenamingItem = false;

// Re-focus selected list item
GridViewItem gridViewItem = FileList.ContainerFromItem(RenamingItem) as GridViewItem;
gridViewItem?.Focus(FocusState.Programmatic);
}

private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
Expand Down