@@ -372,13 +372,6 @@ protected virtual void BaseFolderSettings_LayoutModeChangeRequested(object? send
372
372
373
373
if ( layoutType != ParentShellPageInstance . CurrentPageType )
374
374
{
375
- // Layout changes can cause the active pane to lose focus. To prevent this,
376
- // the pane is locked here and focus is restored when file loading completes
377
- // in the RefreshItem() method in BaseLayoutPage.cs.
378
- // See https://github.com/files-community/Files/issues/15397
379
- // See https://github.com/files-community/Files/issues/16530
380
- ParentShellPageInstance ! . PaneHolder . LockActivePane ( ) ;
381
-
382
375
ParentShellPageInstance . NavigateWithArguments ( layoutType , new NavigationArguments ( )
383
376
{
384
377
NavPathParam = navigationArguments ! . NavPathParam ,
@@ -395,6 +388,12 @@ protected virtual void BaseFolderSettings_LayoutModeChangeRequested(object? send
395
388
}
396
389
397
390
ParentShellPageInstance . ShellViewModel . UpdateEmptyTextType ( ) ;
391
+
392
+ // Focus on the active pane in case it was lost during the layout switch.
393
+ // Allthough the focus is also set from SetSelectedItemsOnNavigation,
394
+ // that is only called when switching between a Grid based layout and Details,
395
+ // not between different Grid based layouts (eg. List and Cards).
396
+ ParentShellPageInstance ! . PaneHolder . FocusActivePane ( ) ;
398
397
}
399
398
}
400
399
@@ -513,7 +512,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
513
512
BaseContextMenuFlyout . Opening += BaseContextFlyout_Opening ;
514
513
}
515
514
516
- public void SetSelectedItemsOnNavigation ( )
515
+ public async void SetSelectedItemsOnNavigation ( )
517
516
{
518
517
try
519
518
{
@@ -527,12 +526,21 @@ navigationArguments.SelectItems is not null &&
527
526
] ;
528
527
529
528
ItemManipulationModel . SetSelectedItems ( listedItemsToSelect ) ;
530
- ItemManipulationModel . FocusSelectedItems ( ) ;
529
+
530
+ // Don't focus file list if TextBox is focused
531
+ if ( FocusManager . GetFocusedElement ( ) is not TextBox )
532
+ ItemManipulationModel . FocusSelectedItems ( ) ;
531
533
}
532
- else if ( navigationArguments is not null && navigationArguments . FocusOnNavigation )
534
+ else if ( navigationArguments is not null && ParentShellPageInstance ! . InstanceViewModel . FolderSettings . LayoutMode is not FolderLayoutModes . ColumnView )
533
535
{
534
- // Set focus on layout specific file list control
535
- ItemManipulationModel . FocusFileList ( ) ;
536
+ // Delay to ensure the new layout is loaded
537
+ if ( navigationArguments . IsLayoutSwitch )
538
+ await Task . Delay ( 100 ) ;
539
+
540
+ // Focus on the active pane in case it was lost during navigation
541
+ // Don't focus file list if TextBox is focused
542
+ if ( FocusManager . GetFocusedElement ( ) is not TextBox )
543
+ ParentShellPageInstance ! . PaneHolder . FocusActivePane ( ) ;
536
544
}
537
545
}
538
546
catch ( Exception ) { }
@@ -1246,14 +1254,6 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
1246
1254
await ParentShellPageInstance ! . ShellViewModel . LoadExtendedItemPropertiesAsync ( listedItem ) ;
1247
1255
if ( ParentShellPageInstance . ShellViewModel . EnabledGitProperties is not GitProperties . None && listedItem is IGitItem gitItem )
1248
1256
await ParentShellPageInstance . ShellViewModel . LoadGitPropertiesAsync ( gitItem ) ;
1249
-
1250
- // Layout changes can cause the active pane to lose focus. To prevent this,
1251
- // the pane is locked in LayoutModeChangeRequested() and focus is restored here
1252
- // when file loading completes.
1253
- // See https://github.com/files-community/Files/issues/15397
1254
- // See https://github.com/files-community/Files/issues/16530
1255
- if ( ParentShellPageInstance . IsCurrentPane && ParentShellPageInstance . InstanceViewModel . FolderSettings . LayoutMode is not FolderLayoutModes . ColumnView )
1256
- ItemManipulationModel . FocusFileList ( ) ;
1257
1257
} ) ;
1258
1258
}
1259
1259
}
0 commit comments