Skip to content

Commit 008bb50

Browse files
authored
Fix: Fixed issue where scroll position wasn't always in the correct position (#15281)
1 parent 66556cb commit 008bb50

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

src/Files.App/Data/Models/ItemManipulationModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public sealed class ItemManipulationModel
2323

2424
public event EventHandler<ListedItem> ScrollIntoViewInvoked;
2525

26+
public event EventHandler ScrollToTopInvoked;
27+
2628
public event EventHandler SetDragModeForItemsInvoked;
2729

2830
public event EventHandler RefreshItemsOpacityInvoked;
@@ -104,6 +106,11 @@ public void ScrollIntoView(ListedItem item)
104106
ScrollIntoViewInvoked?.Invoke(this, item);
105107
}
106108

109+
public void ScrollToTop()
110+
{
111+
ScrollToTopInvoked?.Invoke(this, EventArgs.Empty);
112+
}
113+
107114
public void SetDragModeForItems()
108115
{
109116
SetDragModeForItemsInvoked?.Invoke(this, EventArgs.Empty);

src/Files.App/Views/Layouts/BaseGroupableLayoutPage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public BaseGroupableLayoutPage() : base()
4747
protected abstract void ItemManipulationModel_RemoveSelectedItemInvoked(object? sender, ListedItem e);
4848
protected abstract void ItemManipulationModel_FocusSelectedItemsInvoked(object? sender, EventArgs e);
4949
protected abstract void ItemManipulationModel_ScrollIntoViewInvoked(object? sender, ListedItem e);
50+
protected abstract void ItemManipulationModel_ScrollToTopInvoked(object? sender, EventArgs e);
5051
protected abstract void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e);
5152
protected abstract void EndRename(TextBox textBox);
5253

@@ -70,6 +71,7 @@ protected override void HookEvents()
7071
ItemManipulationModel.FocusSelectedItemsInvoked += ItemManipulationModel_FocusSelectedItemsInvoked;
7172
ItemManipulationModel.StartRenameItemInvoked += ItemManipulationModel_StartRenameItemInvoked;
7273
ItemManipulationModel.ScrollIntoViewInvoked += ItemManipulationModel_ScrollIntoViewInvoked;
74+
ItemManipulationModel.ScrollToTopInvoked += ItemManipulationModel_ScrollToTopInvoked;
7375
ItemManipulationModel.RefreshItemThumbnailInvoked += ItemManipulationModel_RefreshItemThumbnail;
7476
ItemManipulationModel.RefreshItemsThumbnailInvoked += ItemManipulationModel_RefreshItemsThumbnail;
7577
}
@@ -88,6 +90,7 @@ protected override void UnhookEvents()
8890
ItemManipulationModel.FocusSelectedItemsInvoked -= ItemManipulationModel_FocusSelectedItemsInvoked;
8991
ItemManipulationModel.StartRenameItemInvoked -= ItemManipulationModel_StartRenameItemInvoked;
9092
ItemManipulationModel.ScrollIntoViewInvoked -= ItemManipulationModel_ScrollIntoViewInvoked;
93+
ItemManipulationModel.ScrollToTopInvoked -= ItemManipulationModel_ScrollToTopInvoked;
9194
ItemManipulationModel.RefreshItemThumbnailInvoked -= ItemManipulationModel_RefreshItemThumbnail;
9295
ItemManipulationModel.RefreshItemsThumbnailInvoked -= ItemManipulationModel_RefreshItemsThumbnail;
9396
}

src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ protected override void ItemManipulationModel_ScrollIntoViewInvoked(object? send
109109
}
110110
}
111111

112+
protected override void ItemManipulationModel_ScrollToTopInvoked(object? sender, EventArgs e)
113+
{
114+
ContentScroller?.ChangeView(null, 0, null, true);
115+
}
116+
112117
protected override void ItemManipulationModel_FocusSelectedItemsInvoked(object? sender, EventArgs e)
113118
{
114119
if (SelectedItems?.Any() ?? false)

src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ protected override void ItemManipulationModel_ScrollIntoViewInvoked(object? send
9898
ContentScroller?.ChangeView(null, FileList.Items.IndexOf(e) * RowHeight, null, true); // Scroll to index * item height
9999
}
100100

101+
protected override void ItemManipulationModel_ScrollToTopInvoked(object? sender, EventArgs e)
102+
{
103+
ContentScroller?.ChangeView(null, 0, null, true);
104+
}
105+
101106
protected override void ItemManipulationModel_FocusSelectedItemsInvoked(object? sender, EventArgs e)
102107
{
103108
if (SelectedItems?.Any() ?? false)

src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ protected override void ItemManipulationModel_ScrollIntoViewInvoked(object? send
9090
FileList.ScrollIntoView(e);
9191
}
9292

93+
protected override void ItemManipulationModel_ScrollToTopInvoked(object? sender, EventArgs e)
94+
{
95+
if (FolderSettings?.LayoutMode is FolderLayoutModes.ListView)
96+
ContentScroller?.ChangeView(0, null, null, true);
97+
else
98+
ContentScroller?.ChangeView(null, 0, null, true);
99+
}
100+
93101
protected override void ItemManipulationModel_FocusSelectedItemsInvoked(object? sender, EventArgs e)
94102
{
95103
if (SelectedItems.Any())

src/Files.App/Views/Shells/BaseShellPage.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ protected void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoad
659659
break;
660660
case ItemLoadStatusChangedEventArgs.ItemLoadStatus.Complete:
661661
SetLoadingIndicatorForTabs(false);
662+
663+
if (ContentPage is not null)
664+
ContentPage.ItemManipulationModel.ScrollToTop();
665+
662666
ToolbarViewModel.CanRefresh = true;
663667
// Select previous directory
664668
if (!string.IsNullOrWhiteSpace(e.PreviousDirectory) &&
@@ -694,13 +698,10 @@ protected void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoad
694698

695699
var itemToSelect = FilesystemViewModel.FilesAndFolders.ToList().FirstOrDefault((item) => item.ItemPath == folderToSelect);
696700

697-
if (itemToSelect is not null && ContentPage is not null)
701+
if (itemToSelect is not null && ContentPage is not null && userSettingsService.FoldersSettingsService.ScrollToPreviousFolderWhenNavigatingUp)
698702
{
699-
if (userSettingsService.FoldersSettingsService.ScrollToPreviousFolderWhenNavigatingUp)
700-
{
701-
ContentPage.ItemManipulationModel.SetSelectedItem(itemToSelect);
702-
ContentPage.ItemManipulationModel.ScrollIntoView(itemToSelect);
703-
}
703+
ContentPage.ItemManipulationModel.SetSelectedItem(itemToSelect);
704+
ContentPage.ItemManipulationModel.ScrollIntoView(itemToSelect);
704705
}
705706
}
706707
break;

0 commit comments

Comments
 (0)