浏览代码

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

https://winscp.net/tracker/2402

Source commit: 8bbd943bdcf79a1762468f36a7a4611e4235058b
Martin Prikryl 1 周之前
父节点
当前提交
f4d4fbfd21
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      source/packages/filemng/CustomDirView.pas

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

@@ -3402,10 +3402,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;