Skip to content

Commit

Permalink
Fix files-community#15048: Home key didn't move to first character wh…
Browse files Browse the repository at this point in the history
…en renaming item in List View Layout. The Home and end key weren't being acknowledged by the textBox.Keydown on the List View, Grid View and Tile View Layouts. To fix this I replaced it with textBox.PreviewKeyDown, this way the handling is not being consumed before it reaches the controller. I had to implement specific handling for these keys on the switch case already implemented on the GridLayoutPage.xaml.cs.
  • Loading branch information
nunescostr committed Apr 5, 2024
1 parent be0ab46 commit bcd8050
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Files.App/Views/Layouts/BaseGroupableLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected virtual void StartRenameItem(string itemNameTextBox)

textBox.Focus(FocusState.Pointer);
textBox.LostFocus += RenameTextBox_LostFocus;
textBox.KeyDown += RenameTextBox_KeyDown;
textBox.PreviewKeyDown += RenameTextBox_KeyDown;

int selectedTextLength = SelectedItem.Name.Length;

Expand Down Expand Up @@ -317,6 +317,14 @@ protected async void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
case VirtualKey.Right:
e.Handled = (textBox.SelectionStart + textBox.SelectionLength) == textBox.Text.Length;
break;
case VirtualKey.Home:
textBox.SelectionStart = 0;
e.Handled = true;
break;
case VirtualKey.End:
textBox.SelectionStart = textBox.Text.Length;
e.Handled = true;
break;
case VirtualKey.Tab:
textBox.LostFocus -= RenameTextBox_LostFocus;

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ override public void StartRenameItem()

textBox.Focus(FocusState.Pointer);
textBox.LostFocus += RenameTextBox_LostFocus;
textBox.KeyDown += RenameTextBox_KeyDown;
textBox.PreviewKeyDown += RenameTextBox_KeyDown;

int selectedTextLength = RenamingItem.Name.Length;
if (!RenamingItem.IsShortcut && UserSettingsService.FoldersSettingsService.ShowFileExtensions)
Expand Down

0 comments on commit bcd8050

Please sign in to comment.