Jelajahi Sumber

Bug 1891: Correct letter case variant of remote directory in directory tree was not always selected

https://winscp.net/tracker/1891

Source commit: ef7c94034eaa43964a021298eb0e93017730fd19
Martin Prikryl 5 tahun lalu
induk
melakukan
ce46019d48
1 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 16 1
      source/components/UnixDriveView.cpp

+ 16 - 1
source/components/UnixDriveView.cpp

@@ -777,7 +777,8 @@ TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
     {
       UnicodeString DirName = UnixExtractFileName(Path);
       int StartIndex = 0;
-      int EndIndex = Parent->Count - 1;
+      int LastIndex = Parent->Count - 1;
+      int EndIndex = LastIndex;
 
       while (true)
       {
@@ -786,6 +787,20 @@ TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
         int C = DoCompareText(DirName, NodeDir);
         if (C == 0)
         {
+          // In case there are more items that are case insensitivelly or logically equivalent,
+          // walk back to find the first such one and then walk forward through all such items,
+          // looking for an exact binary match.
+          // If so such match is found (can it even happen?), return the last equivalent item.
+          while ((Index > 0) && (DoCompareText(DirName, Parent->Item[Index - 1]->Text) == 0))
+          {
+            Index--;
+          }
+          while (!SameStr(DirName, Parent->Item[Index]->Text) &&
+                 (Index < LastIndex) &&
+                 (DoCompareText(DirName, Parent->Item[Index + 1]->Text) == 0))
+          {
+            Index++;
+          }
           Result = Parent->Item[Index];
           break;
         }