Browse Source

Issue 2402 – Failure after reloading file panel when number of files decreases

https://winscp.net/tracker/2402
(cherry picked from commit f4d4fbfd21a5bf04d76f026909709d9e4bee6017)

# Conflicts:
#	source/packages/my/NortonLikeListView.pas

Source commit: f90e2f6378b003375dd93adae2b4ea4c10d86071
Martin Prikryl 1 week ago
parent
commit
2969212072
1 changed files with 9 additions and 3 deletions
  1. 9 3
      source/packages/filemng/CustomDirView.pas

+ 9 - 3
source/packages/filemng/CustomDirView.pas

@@ -3455,10 +3455,16 @@ begin
   if Assigned(ItemToFocus) then
   begin
     // we have found item that was previously focused and visible, scroll to it
-    if (ViewStyle = vsReport) and FocusedShown and
-       (ItemToFocus.Index > ShownItemOffset) then
+    if (ViewStyle = vsReport) and FocusedShown then
     begin
-      MakeTopItem(Items[ItemToFocus.Index - ShownItemOffset]);
+      var Index := ItemToFocus.Index - ShownItemOffset;
+      // Seen a situation when the the first (index 0, ..) item was focused and IsItemVisible,
+      // yet TopItem was index 1. So we end p here with -1
+      if (Index >= 0) and (Index < Items.Count) then
+      begin
+        var Item := Items[Index];
+        MakeTopItem(Item);
+      end;
     end;
     // Strangely after this mouse selection works correctly, so we do not have to call FocusItem.
     ItemFocused := ItemToFocus;